mongoskin

What is the difference between safe:true and safe:false in a connection with mongoskin? and how use it?

早过忘川 提交于 2020-01-23 21:28:46
问题 I have a connection with mongoskin and nodejs: var db = mongo.db("root:toor@127.0.0.1:27017/cordoba"); but I don't know which is the best practice in this case... db.collection('usuarios').insert(campos,{safe:true}, function(err, result) I want to insert campos in mongodb, I'm using safe:true... so what happens if I use safe:false, and what is the best practice? this: var db = mongo.db("root:toor@127.0.0.1:27017/cordoba"); db.collection('usuarios').insert(campos,{safe:true}, function(err,

How to get a instance of db from node-mongo native driver?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 06:31:27
问题 Consider, I have MongoDB connection opened in the main app.js file itself and the following code fall in it's call back: mongodb.connect('MongoDBUrlGoesHere', function (err, db) { app.listen(app.get('port'), function AppListnCB() { console.log("Server listening on port " + app.get('port')); }); }); This is all done to have only one db instance across the application. Now, If we are in another external.js file and need a same db object which is aleady has connected. This can be done very

Finding a MongoDB document through a word in a field description in each product with Mongoskin

老子叫甜甜 提交于 2020-01-04 13:37:57
问题 This is an example of document that I have in my MongoDB: { "_id": ObjectId('5525039895884d66710d0fc3'), "prid": "63527", "data": { "sku": "HF22-81639", "name": "Product Test", "ean": "8763900872512", "description": "This product is my first test", } } This search for "description" does not work (this is where I need help): app.get("/description/:id", auth, function(req, res, next) { req.collection.findOne({ "data.description": req.params.id }, function(e, result) { if(e) return next(e); res

Finding a MongoDB document through a word in a field description in each product with Mongoskin

。_饼干妹妹 提交于 2020-01-04 13:37:19
问题 This is an example of document that I have in my MongoDB: { "_id": ObjectId('5525039895884d66710d0fc3'), "prid": "63527", "data": { "sku": "HF22-81639", "name": "Product Test", "ean": "8763900872512", "description": "This product is my first test", } } This search for "description" does not work (this is where I need help): app.get("/description/:id", auth, function(req, res, next) { req.collection.findOne({ "data.description": req.params.id }, function(e, result) { if(e) return next(e); res

How to check if Mongo's $addToSet was a duplicate or not

淺唱寂寞╮ 提交于 2019-12-30 09:43:12
问题 I am using Mongoskin + NodeJS to add new keywords to my MongoDB. I want to notify the user that the entry was a duplicate but not sure how to do this. /* * POST to addkeyword. */ router.post('/addkeyword', function(req, res) { var db = req.db; db.collection('users').update({email:"useremail@gmail.com"}, {'$addToSet': req.body }, function(err, result) { if (err) throw err; if (!err) console.log('addToSet Keyword.' ); }); }); The result does not seem to be of any use to me since it doesn't tell

MongoDB _id is convert to ObjectID automatically, but sometime it is not.

偶尔善良 提交于 2019-12-25 03:44:33
问题 I am using a wrapper called mongoskin to access mongoDB. mongoskin is a simple wrapper around mongoDB javascript api. But when I write to mongoDB, sometimes _id is converted to ObjectID, sometime is it not. The different behavior causes many problem when I have to compare _id. For example: The following documents in company collection, "creator" is not converted to ObjectID, but item in "clients" is converted to ObjectID automatically. > db.company.find() { "_id" : ObjectId(

Node.js promises with mongoskin

非 Y 不嫁゛ 提交于 2019-12-22 07:48:08
问题 I'm trying to avoid using callbacks when making mongodb queries. I'm using mongoskin to make calls like so: req.db.collection('users').find().toArray(function (err, doc) { res.json(doc); }); In many cases I need to make multiple queries so I want to use Node.js promise library but I'm not sure how to wrap these functions as promises. Most of the examples I see are trivial for things like readFile , I'm guessing in this case I would need to wrap toArray somehow? Can this be done or would have

mongoskin and bulk operations? (mongodb 3.2, mongoskin 2.1.0 & 2.2.0)

纵然是瞬间 提交于 2019-12-12 02:13:56
问题 I've read the various bits of literature, and I'm seeing the same problem that the questioner in https://stackoverflow.com/a/25636911 was seeing. My code looks like this: coll = db.collection('foobar'); bulk = coll.initializeUnorderedBulkOp(); for entry in messages { bulk.insert(entry); } bulk.execute(function (err, result) { if (err) throw err inserted += result.nInserted }); bulk is an object bulk.insert works just fine bulk.execute is undefined The answer in the stackoverflow question said

Using wait.for with nodejs and mongoskin to avoid callback hell

≡放荡痞女 提交于 2019-12-11 22:37:14
问题 I m actually developping a little application with mongodb and nodejs to create my REST Api. I face a problem when I need to access an object reference : I have a roadmap collection which reference a user object When I want to get all the roadmaps, I have to loop on my roadmap array to lazy load my users, by the ref ID stored in the roadmap collection I have a callback problem, the user is not loaded when I need it I have found a solution using Wait.for library : https://github.com/luciotato

Is there a way to list collections with mongoskin?

我怕爱的太早我们不能终老 提交于 2019-12-07 21:41:58
问题 I already have an established database connection. I need to list the names of the collections in the database. Is it possible? 回答1: To show collections into database from mongo shell : db.getCollectionNames() So to show collection in mongoskin try that var collections = db.collections(); collections.each(function(err, collection) { console.log(collection); }); according to this link Mongoskin Tutorial 回答2: db.collectionNames(function(err, collectionArrayResult) { //Now do something with