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
1 answer

Synchroneous call with mongodbnative

I have the following problem with mongodb-native. I have a function whose purpose is to return some element from db. function get(){ db.collection('test').findOne({...},{...},function(err, doc){ // my doc is here }); // but here my doc is…
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
0
votes
0 answers

ensureIndex causes error

This is my code: this._db = db; this._collection = this._db.collection("Topics"); this._collection.ensureIndex( { slug: 1 }, { unique: true }, function(error) { if (error) { console.error(error); }}); When I use an…
Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160
0
votes
1 answer

understand the connect-mongo usage, how to use connect-mongo for sessions

I'm in a node.js app, and I'm trying to get the session data to store in a mongoDB database. But the I dont understand the usage of connect-mongo and I would like if someone could explain to me the correct usage and what I can't connect to my…
Edu
  • 460
  • 12
  • 34
0
votes
2 answers

Cannot applying find() method with Native MongoDB becaus of ID type

I have a function that is needed to get results. When I give 1 as _id filter everything is OK. collectionPersonnel .find({ '_id' : 1 }) .toArray(function (err, personnel) { console.log(personnel); }); If I give filter another way…
efkan
  • 12,991
  • 6
  • 73
  • 106
0
votes
1 answer

How to assign query results to an object

I am trying to transfer results data from query function to an object. console.log(results) line returns 'undefined' result. What should I do? module.exports = { show: function(req, res) { var results; …
efkan
  • 12,991
  • 6
  • 73
  • 106
0
votes
1 answer

espressjs, node, mongo saving method

i have this function "saveUser", which gets value from textbox, and updates information of the user and then uses ajax to post the object to our updateuser service. function saveUser(event){ event.preventDefault(); var errorCount = 0; …
sonjasan
  • 49
  • 5
0
votes
1 answer

MongoError: Connection Closed By Application

I'm trying to update the states with the highest weather, adding a field, but when i try to do the loop, the connection gets closed! It only do the first update, but the next it says MongoError: Connection Closed By Application Why? I'm not closing…
Cris_Towi
  • 615
  • 1
  • 13
  • 25
0
votes
1 answer

Query embedded collection in a sails project with mongodb

I'm using sails-mongo in my project and i need to execute one query in an embedded collection. My data are something like the following: { "_id" : ObjectId("53906c6254f36df504e99b8f"), "title" : "my post" "comments" : [ { …
Victor
  • 5,043
  • 3
  • 41
  • 55
0
votes
1 answer

MongoDB initial record does not delete

I have an app with Mongoose, Node and Backbone. I have set up a delete method to remove items from an array by "id". Everything works as it should except for the initial record - it cannot be deleted. Here is the error message when I try to delete:…
0
votes
1 answer

Preserving Execution order in nested for loop and callbacks in NodeJS MongoDB

Scenario: There are users and users has many posts. For a particular group of users, I need to fetch 10 recent posts per user and send them in response. Here is what I have come up with: users is array having user info. var allPosts = []; for(var…
Avdhesh Parashar
  • 1,167
  • 2
  • 8
  • 10
0
votes
1 answer

What does err and doc mean in cursor.toArray(function(err, docs){})?

This is from official MongoDB documentation. toArray cursor.toArray(function(err, docs){}) converts the cursor object into an array of all the matching records. Probably the most convenient way to retrieve results but be careful with large datasets…
geoyws
  • 3,326
  • 3
  • 35
  • 47
0
votes
1 answer

node-mongodb-native remove by DBRef $id (dot issue)

I have 2 collections in my mongodb database: users and posts. And in posts collection I have DBRef field like this: user : DBRef('users', ObjectId('...'), null) When I'm going to remove some post by user id, I do the following: db.posts.remove({…
oleh.meleshko
  • 4,675
  • 2
  • 27
  • 40
0
votes
3 answers

mongodb - validation before adding user

Thats how I add a user object to my mongoDB. How to check if there is already another user with the same email address? I could fetch all users and look it up, but I want to have a better performance solution for that. /* POST to Add User Service…
Robin Wieruch
  • 14,900
  • 10
  • 82
  • 107
0
votes
1 answer

Render collection data from mongo db in node application

I am developing a Node.js/Backbone.js SPA and moving some of my data from JSON files to Mongo. I have set up an api with Mongoose and my data is posting to the server. However, when I try to fetch the data from Mongo it only returns the last item in…
Sizzles27
  • 94
  • 12
0
votes
2 answers

Using MongoDB Native Dot Notation with variable

I have following command: collection.update( { "facebook_id": req.params.facebook_id }, { "$push": { "circles.0.messages": message } }, function(err) {...}); That works fine. But I need the 0 to be a variable. As soon as I change it…
Luxori
  • 115
  • 7