Questions tagged [node-mongodb-native]

The MongoDB Native Node.js driver is an officially supported driver providing a native asynchronous Node.js interface to MongoDB. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoose.

The MongoDB Native Node.js driver is an officially supported driver written in pure JavaScript to provide a native asynchronous Node.js interface to MongoDB. The driver is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoose ODM.

Installing/upgrading

The easiest way to install the driver is to use npm:

$ npm install mongodb

Documentation

3.0 Driver

2.2 Driver

Related links

482 questions
0
votes
2 answers

Use cursor methods along with mongodb command in node

I am working on a location based app in nodejs. I am using - mongodb v2.4.4 - the native nodejs mongodb driver (https://github.com/mongodb/node-mongodb-native) - nodejs version 0.10.0 I have geospatial indexes (2dsphere) in all the documents of one…
Shuaib
  • 779
  • 2
  • 13
  • 47
0
votes
1 answer

Mongodb, how do I aggregate match / group some documents but only if one or other conditions are satisfied?

I have two properties b and u that are arrays. I want my query to return me all documents that have at least 1 element in b that satisfies condition 1 or at least 1 element in u that satisfied condition 2. My problem is that if condition 1 is…
Discipol
  • 3,137
  • 4
  • 22
  • 41
0
votes
0 answers

Mongodb: Converting list of elements from array structure into object structure for update purposes

I have a collection of documents where each holds a "list" property. This list is an array of unique objects (I generated an ObjectID for each of them). We will call them listElements. Now. I need to update 1 or more elements in the same query. I DO…
Discipol
  • 3,137
  • 4
  • 22
  • 41
0
votes
1 answer

How do I update 2 specific elements in an array with 2 different values?

I have a document of the sorts: { _id:ObjectID, list:Array } And the list contains elements of the form (which I will refer to as listElement): { _id:ObjectID, time:Number } I want to update the time subfield of 2 specific listElements each with…
Discipol
  • 3,137
  • 4
  • 22
  • 41
0
votes
1 answer

node.js write mongoDB collection to file using Streams?

I'm playing around with node.js and streams trying to dump an entire mongoDB collection to a file but it isn't working. I suspect it has something to do with old style streams and 0.10 streams but I could be wrong. The code below can also be found…
poorman
  • 120
  • 7
0
votes
2 answers

node-mongodb-native creates sequential object ids

Somehow mongod-native creates sequential object ids for inserted objects. I would prefer it if the database could do this job, or mongodb-native could at least use the same generation strategy as the db does. Inserting with mongodb-native…
thertweck
  • 1,120
  • 8
  • 24
0
votes
1 answer

TTL index for users collection

I have 'users' collections with the following structure: _id: ObjectId(...), name: 'Erik', email: 'erik@mail.com' I need to use signup confirmation via email, so I need yours advice for the following approach: Create TTL index on that collection…
Erik
  • 14,060
  • 49
  • 132
  • 218
0
votes
2 answers

mongodb update array any matching index

I have a data structure like this: { students: [ { name: "john", school: 102, age: 4 }, { name: "jess", school: 102, age: 11 }, { name: "jeff", school: 108, age: 7 } ] } { students: [ …
Harry
  • 52,711
  • 71
  • 177
  • 261
0
votes
1 answer

Multiple connections with node-mongodb-native

I am working on a function to insert a document in a mongoDb database using the node-mongodb-native module. Everything is working, except if I call insert multiple documents back-to-back. I use a for loop to test how my function is reacting to…
Maxime
  • 2,192
  • 1
  • 18
  • 23
0
votes
1 answer

Upsert into Mongo based on date?

obj = { date: 137097408891, id: '1234', value: 'value' } What I want to do it apply the value field to the object with the id, only if the date is newer then the current one saved. If no document with that ID is saved, just save this one.…
boom
  • 10,856
  • 9
  • 43
  • 64
0
votes
1 answer

Wrapping thrown errors so they don't crash the node webserver (node-mongodb-native)

Simplified code... but the basic scenario is I'm doing a findOne query with Mongo to lookup a user, but if the user doesn't exist it throws an error that crashes the entire webserver. Can someone point me in the right direction for correctly…
Msencenb
  • 5,675
  • 11
  • 52
  • 84
0
votes
1 answer

Is it possible to return only a certain fields when inserting a new document?

I nedd to get the new document back with _id field only. Something like this: db.users.insert({name: 'Jonh', age: 27}, {_id: true} , function (err, user) { if (err) {} // need to be user with only _id field. }); How can I do this?
Erik
  • 14,060
  • 49
  • 132
  • 218
0
votes
1 answer

Is it bad idea to use custom pk as string?

Let me explain the problem. I use node-mongodb-native as mongodb driver and every time I need to make find query by _id field I have to convert it to ObjectId like the following: var ObjectID = require('mongodb').ObjectID; db.collection.find({_id:…
Erik
  • 14,060
  • 49
  • 132
  • 218
0
votes
1 answer

node-mongodb-native save method

https://github.com/mongodb/node-mongodb-native Save The save method is a shorthand for upsert if the document contains an _id, or an insert if there is no _id. As it says on that page the save method is a shorthand. But there's no example, how…
Harry
  • 52,711
  • 71
  • 177
  • 261
0
votes
1 answer

Inserted inside the callback function of the query execution action

db.createCollection("category",function(errDb,collection){ collection.findOne({name:"test"},function(err,value){ if(value == null) { collection.insert({name:"test"}) } }) }) Error: Cannot use a…
Xingjia Luo
  • 381
  • 1
  • 3
  • 11