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

Mongoose expires property not working properly

the answer So it turns out when I was testing using the expires property in Mongoose, I successfully set a TTL index in the database, but didn't realize that when I changed the time in my mongoose schema I'd need to delete the previous TTL index out…
adrian_reimer
  • 459
  • 5
  • 10
8
votes
1 answer

How to register and use mongoose-deep-populate

okay. so I'm trying to do some nested population of my mongoose models. And I found that Mongoose-Deep-Populate was one of the easiest fixes for the nested solution, however, as easy as it might seem, I can't figure out how to register the plugin…
Michael Tot Korsgaard
  • 3,892
  • 11
  • 53
  • 89
8
votes
1 answer

Not authorized for query on Mongodb shard from Mongoose driver

I am using mongoDB 2.6.7 and mongoose 3.8.23 driver for node.js. Database is sharded in 2 shards (each is separate replica) and everything looks ok when I enter mongo shell on any of instance, replica, mongos, config servers etc. After that I have…
Ivan Longin
  • 3,207
  • 4
  • 33
  • 42
8
votes
1 answer

MongoDB Chat Schema

Im trying MongoDB and as a matter of starting point im creating a schema for a chat application that may be simple to scale in the future, so im wondering if this looks correct from what i have been seeing in the docs. So far i have 3 collections…
Andrés Da Viá
  • 586
  • 1
  • 8
  • 24
8
votes
1 answer

Mongoose .find() method causes requests to hang

I have this route defined, but any requests made to it get's stuck on 'pending' and runs forever. When I log the code, I see 1 followed by 4, which means the code inside the find method never gets executed # Calendar routes router.get…
Tarlen
  • 3,657
  • 8
  • 30
  • 54
8
votes
1 answer

Mongoose MongoDB: updating objects in a nested array

I've got the following schema var UserSchema = new Schema({ emp_no: Number, skills: [{ skill: { type: Schema.Types.ObjectId, ref: 'Skill' }, startDate: {type: Date}, }] }); I'm then trying to update the startDate of…
DianeH
  • 247
  • 1
  • 3
  • 12
8
votes
2 answers

Atomic multiple operations in Mongoose

Consider a schema: var userSchema = mongoose.Schema({ ... followers: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }], following: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }] ... } When userA follows userB, userB is to be pushed…
k88074
  • 2,042
  • 5
  • 29
  • 43
8
votes
4 answers

Location in mongoose, mongoDB

Whenever I try to store a location in my mongodb it doesn't show, so I guess I'm doing something wrong. I can't find any documentation on how to store a location in mongoose so I'm just gonna ask it here. I first create my model: var eventSchema =…
Laurenswuyts
  • 2,144
  • 4
  • 21
  • 39
8
votes
2 answers

What are best practices for partitioning data in MongoDB?

I'm creating a social site using mean stack and I need some suggestions regarding mongoDB and mongoose. I'm part of a startup and we decided to use these amazing technologies to fulfil our task. Basically, I need some suggestions. Currently, I have…
Aleksandar Grbic
  • 203
  • 1
  • 3
  • 13
8
votes
2 answers

Default value not set while using Update with Upsert as true

I have the following model for users: var UserSchema = new mongoose.Schema({ name: String, dob: Date, sex: String, photo: String, email: {type: String, index: {unique: true, required: true}}, created: {type: Date, default:…
ZeMoon
  • 20,054
  • 5
  • 57
  • 98
8
votes
2 answers

MongoDB Read/Write Locks

I'm planning to create an application using nodejs that users can rate the products. From what I heard locks are different in mongodb than mySql. I'm worried that if let's say 10 users vote on a product at a same time, Mongodb can't handle it and…
Hirad Roshandel
  • 2,175
  • 5
  • 40
  • 63
8
votes
3 answers

Save document to specific collection in mongoose

I'm having trouble trying understand which is the collection I'm saving the document to. I have the following piece of code: var message = mongoose.Schema({ created: {type: Date, default: Date.now} }); var message_temp =…
extremeMeta
  • 93
  • 1
  • 1
  • 7
8
votes
3 answers

Winston Logging with Mongoose Docs

I recently just switched over to Winston for logging and noticed an issue when logging mongoose docs after an exec. Example: Model.find().exec(function (err, docs) { console.log(docs) // Prints the collection fine winston.info(docs) //…
iQ.
  • 3,811
  • 6
  • 38
  • 57
8
votes
2 answers

Mongoose asynchronous multiple save conflicts

I've a big logic problem using Node/Mongoose/Socket.io ... Let's say I got a Server model which is often called at the same time in my application, some calls involve updating datas in the model. db.Server.findOne({_id:…
Laurent
  • 2,284
  • 2
  • 21
  • 41
8
votes
1 answer

Lodash merge with mongoose

Here is a code snippet of an update method using express.js and mongoose. I'm trying to merge the existing mongo entity with the json object from the request payload body. exports.update = function(req, res) { if(req.body._id) { delete…
Michael
  • 2,436
  • 1
  • 36
  • 57