Doc:  {    _id: 5150a1199fac0e6910000002,    name: 'some name,    items: [{       id: 23,       name: 'item name 23'    },{       id: 24,       name: 'item name 24'    }] }   Is there a way to pull a specific object from an arra...
I want to drop some mongodb collections, but that's an asynchronous task. The code will be:  var mongoose = require('mongoose');  mongoose.connect('mongo://localhost/xxx');  var conn = mongoose.connection;  ['aaa','b...
I'm trying to select only a specific field with  exports.someValue = function(req, res, next) {     //query with mongoose     var query = dbSchemas.SomeValue.find({}).select('name');      query.exec(function (err, someValue) {         i...
I came across a piece of Mongoose code that included a query findOne and then an exec() function.  Ive never seen that method in Javascript before? What does it do exactly?...
I have the following schemas for the document Folder:  var permissionSchema = new Schema({     role: { type: String },     create_folders: { type: Boolean },     create_contents: { type: Boolean } });  var folderSchema = new Schema({     name: { ty...
To modify a field in an existing entry in mongoose, what is the difference between using  model = new Model([...]) model.field = 'new value'; model.save();   and this  Model.update({[...]}, {$set: {field: 'new value'});   The reason...
I'm trying to dynamically create _id's for my Mongoose models by counting the documents in the db, and using that number to create the _id (assuming the first _id is 0). However, I can't get the _id to set from my values. Here's my...
Is there something that I'm missing that would allow item to log as an object with a parameter, but when I try to access that parameter, it's undefined?  What I've tried so far:   console.log(item) => { title: "foo", content:...
I have server.js and db.js The db.js file interacts with my database using Mongoose and I use server.js to call functions from db.js :  var mongoose = require('mongoose'); mongoose.connect('', { useNewUrlParser: true }) var Schema =...
I have the following simple shema:   var userSchema = new Schema({     name : String,    age: Number,    _creator: Schema.ObjectId   });    var User = mongoose.model('User',userSchema);   What I want to do is create the new document and ret...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.