Tag: mongoose

为什么mongoose总是添加一个s到我的collections名称的末尾

例如,这段代码会创build一个名为“datas”的集合 var Dataset = mongoose.model('data', dataSchema); 而这段代码会产生一个名为“users”的集合 var User = mongoose.model('user', dataSchema); 谢谢

如何从find方法返回Mongoose结果?

我可以find任何与mongoose结果折页的东西说这样做: users.find({}, function(err, docs){ res.render('profile/profile', { users: docs }); }); 我怎么能返回查询的结果,更像这样? var a_users = users.find({}); //non-working example 这样我可以得到多个结果发布在网页上? 喜欢: /* non working example */ var a_users = users.find({}); var a_articles = articles.find({}); res.render('profile/profile', { users: a_users , articles: a_articles }); 可以这样做吗?

Mongoose.js:通过用户名LIKE值查找用户

我喜欢通过寻找一个名为value的用户来在mongoDb中find一个用户。 问题在于: username: 'peter' 是,如果用户名是“彼得”,或“佩特”..或类似的东西,我不会find它。 所以我想要像SQL一样 SELECT * FROM users WHERE username LIKE 'peter' 希望你们能得到我所要求的? 短:mongoose.js / mongodb中的“字段LIKE值”

如何在不定义模式的情况下使用Mongoose?

在之前版本的Mongoose(对于node.js)中,有一个选项可以在不定义模式的情况下使用它 var collection = mongoose.noSchema(db, "User"); 但在目前的版本中,“noSchema”function已被删除。 我的模式可能经常改变,真的不适合定义的模式,所以有没有一种新的方法在mongoose中使用无模式模型?

mongoose(mongodb)批量插入?

Mongoose v3.6 +支持批量插入吗? 我已经search了几分钟,但是与这个查询匹配的任何东西都是几十年,答案是一个明确的不。 编辑: 为了将来的参考,答案是使用Model.create()。 create()接受一个数组作为它的第一个参数,所以你可以传递你的文档作为数组插入。 请参阅http://mongoosejs.com/docs/api.html#model_Model.create

如何在创build后在mongoose中填充子文档?

我正在为item.comments列表添加评论。 在输出响应之前,我需要获取comment.created_by用户数据。 我应该怎么做? Item.findById(req.param('itemid'), function(err, item){ var comment = item.comments.create({ body: req.body.body , created_by: logged_in_user }); item.comments.push(comment); item.save(function(err, item){ res.json({ status: 'success', message: "You have commented on this item", //how do i populate comment.created_by here??? comment: item.comments.id(comment._id) }); }); //end item.save }); //end item.find 我需要在我的res.json输出中填充comment.created_by字段: comment: item.comments.id(comment._id) comment.created_by是我的mongoose CommentSchema中的用户参考。 它目前只给我一个用户ID,我需要填充所有的用户数据,除了密码和盐字段。 这是人们所问的模式: var CommentSchema = new […]

mongodb / mongoose findMany – 查找列表中列出的所有文件

我有一个_id数组,我想相应地获得所有的文档,那么最好的方法是什么? 就像是 … // doesn't work … of course … model.find({ '_id' : [ '4ed3ede8844f0f351100000c', '4ed3f117a844e0471100000d', '4ed3f18132f50c491100000e' ] }, function(err, docs){ console.log(docs); }); 该数组可能包含数百个_ids。

在Mongoose / MongoDB中创build多字段索引

我试图find关于如何在Mongoosejs中创build多字段索引的文档,无济于事。 特别是我有两个领域需要索引和唯一。 什么是一个索引两个字段在一起的示例mongoose模式?

在mongoose,我怎么按datesorting? (的node.js)

比方说,我在Mongoose中运行这个查询: Room.find({}, function(err,docs){ }).sort({date:-1}); 这不行!

MongoDB – 获取集合中每个组的max属性的文档

我的数据如下所示: session, age, firstName, lastName 1, 28, John, Doe 1, 21, Donna, Keren 2, 32, Jenna, Haze 2, 52, Tommy, Lee .. .. 我想要得到每个会话中最大(按年龄)的所有行。 所以对于上面的input,我的输出如下所示: sessionid, age, firstName, lastName 1, 28, John, Doe 2, 52, Tommy, Lee 因为约翰在会议= 1组中的年龄最大,而汤米在会议= 2组中的年龄最大。 我需要将结果导出到一个文件(csv),它可能包含大量的logging。 我怎样才能做到这一点?