Questions tagged [mongoose]

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment.

Documentation

Related links

To open a bug or feature request, visit: https://github.com/Automattic/mongoose/issues

For Mongoose, an embeddable web server written in C, use .

Installations

npm install --save mongoose
46587 questions
8
votes
3 answers

Mongodb takes 3 minutes to connect

Just reinstalled Mongodb on my mac (fresh install of mountain lion 10.8) and now my apps are taking ~3 mins to connect. I put together a simple node script to test this: var start = (new Date()).getTime(); var mongoose = require('mongoose'); var…
wesbos
  • 25,839
  • 30
  • 106
  • 143
8
votes
2 answers

How to avoid fat models in a node.js + mongoose app?

The app is using express 3. Here is a barebones example of a route that fetches data from the database: var Post = mongoose.model('Post') app.get('post/:id/loompas', function(req, res) { Post.getLoompas(function(err, data){ …
Ricardo Tomasi
  • 34,573
  • 2
  • 55
  • 66
8
votes
4 answers

Auto increment document number in Mongo / Mongoose

My app has several users, each user has documents. Each documents needs to have a sequence number, that may look something like this: 2013-1, 2013-2 (year and sequence number), or perhaps just a simple number: 1, 2, 3... Currently, I am assigning…
ragulka
  • 4,312
  • 7
  • 48
  • 73
8
votes
2 answers

Mongoose disconnect does not work

I was trying to disconnect the mongoose connection after finishing the database work, but seems it didn't work var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/myDatabase'); var MyModel = mongoose.model('MyModel',…
Gary
  • 483
  • 2
  • 6
  • 17
8
votes
4 answers

Mongoose variable key name

I have a mongo object and wish to access it via mongoose for my web app. The schema I've defined has an Object storing user ids and a 3-level value (yes, maybe or no). e.g. "user_info": { "": "y", "": "n" } The…
Simon Walker
  • 5,523
  • 6
  • 30
  • 32
8
votes
1 answer

Insert/Update record using mongoose

I am trying to insert a record into mongodb, using mongoose, but the record does not update when record is already in the database. Is there something I am doing wrong? The documentation for mongoose is not the easiest to follow for…
tony2
  • 229
  • 2
  • 4
  • 7
8
votes
1 answer

how do i use should with mocha and mongoose?

I keep getting an error in the save() method when I run the test. var User = require('../../models/user') , should = require('should'); describe('User', function(){ describe('#save()', function(){ it('should save without error',…
chovy
  • 72,281
  • 52
  • 227
  • 295
8
votes
1 answer

Mongoose Pagination and Filters

I'm trying to trying to do pagination with an optional filter option with Mongoose. I have it working with the pagination by making 2 queries to the database, one to get a count of the documents and one to actually get the data. Without pagination,…
Bryan Cheng
  • 148
  • 1
  • 7
8
votes
1 answer

Mongoose findOne function not being executed

... (... = some unrelated code) var mongoose = require('mongoose'); var db = mongoose.connect('mongodb://localhost/test'); ... dataSchema = new Schema({ 'url': { type: String, index: true }, 'user_id': { type: Schema.ObjectId,…
Bob Ren
  • 2,139
  • 2
  • 17
  • 16
8
votes
8 answers

Mongoose JS promises? Or how to manage batch save

How do I manage batch save in Mongoose? I saw it may not be possible yet: How can I save multiple documents concurrently in Mongoose/Node.js? Theres some mention about using some flow control library like q, but I also notice there promises in…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
8
votes
2 answers

NodeJS - MongooseJS schema error that i cant figure out

Maybe a second set of eyes can see what is wrong with my schema var UserSchema = new Schema({ name: { first : {type: String} , last : {type : String} } , …
Vartan Arabyan
  • 2,925
  • 7
  • 25
  • 35
8
votes
2 answers

MongoDB: How can I store files (Word, Excel, etc.)?

I've yet to look into storing files such as Word, Excel, etc. into MongoDB seriously and I want to know - am I able to store whole docx or excel files in MongoDB and then RETRIEVE them via querying?
PinkElephantsOnParade
  • 6,452
  • 12
  • 53
  • 91
8
votes
2 answers

Passport.js and Mongoose.js populate User on login - loses populated field on req.user

Using Mongoose.js, my authenticate method populates the field "companyRoles._company," but the populated data reverts to the company reference ID when I try to access the same populated field in my req.user object. //Authentication…
Mikey
  • 361
  • 3
  • 10
8
votes
1 answer

Why do my MongooseJS ObjectIds fail the equality test?

Suppose I save and retrieve identical objects as follows var obj1, obj2; instance.save(function(err, saved) { obj1 = saved; }); Model.find(obj1._id).run(function(err, retrieved) { obj2 = retrieved; }); When I print to the console,…
deltanovember
  • 42,611
  • 64
  • 162
  • 244
8
votes
1 answer

Mongoose.js: Save with a empty ObjectId

How can I save with a empty ObjectId. I wanna create a item, thats not attach to any user yet. So the owner has to be a empty ObjectId. How to do this?
techbech
  • 3,754
  • 5
  • 20
  • 28