草庐IT

mongoose-orm

全部标签

javascript - Mongoose 错误 : Schema hasn't been registered for model when populate

我正在尝试加入两个集合并能够获取组合数据。为此,使用Mongoose,我应该使用填充语法来实现这一点。我收到未为“User_Fb”注册SchemaSchema的错误消息。从我的代码中,我已经导出了模型并在我的server.js中需要,但错误仍然出现。我做错了什么?feed_post.model.jsvarmongoose=require('mongoose');varconn_new_app=mongoose.createConnection('mongodb://localhost/new_app');varUser_fb=require('../models/fb_db.model

node.js - 如何在 Mongoose 中填充嵌套实体?

我有以下Mongoose模式结构userSchema=newSchema({roles:[role:{type:Schema.Types.ObjectId,ref:'Role'}]})rolesSchema=newSchema({name:String,roleEntities:[{entity:{type:Schema.Types.ObjectId,ref:'RoleEntity'},abilities:[{type:Schema.Types.ObjectId,ref:'Ability'}]}]}roleEntitiesSchema=newSchema({name:String})a

mongodb - 在 Mongoose 中进行小时/日/月/年的范围查询

试图弄清楚如何做到这一点。基本上我想按我提交的时间/天/月/年进行排序。每个submission都有一个created字段,其中包含"created"形式的MongooseDate对象:ISODate("2013-03-11T01:49:09.421Z")。我需要在find()条件下与此进行比较吗?这是我当前的查询(我将它包装在一个计数中以用于FWIW的分页目的,所以忽略该部分):getSubmissionCount({},function(count){//Sortbytherangeswitch(range){case'today':range=now.getTime();case

javascript - 用 express.js 处理 Mongoose 连接的正确方法是什么?

我尝试运行一个非常简单的“server.js”设置:varexpress=require('express'),wines=require('./routes/testscripts');varapp=express();app.get('/first_test',wines.popSingleData);app.listen(3000);console.log('Listeningonport3000...');这是设置为连接到localhost:3000当我导航到localhost:3000/first_test时,它会调用testscript.js中的“popSingleData

node.js - 无法访问 Mongoose 响应的对象属性

我在node.js上运行这段代码varmongoose=require('mongoose');mongoose.model('participant',newmongoose.Schema({},{collection:'forumParticipant'}));varParticipant=mongoose.model('participant');mongoose.connect('******');Participant.find({entity_id:0},function(err,docs){console.log(docs[0]);console.log(docs[0].

node.js - Mongoose 实例 .save() 不工作

我对Mongoose和MongoDb有疑问非常有趣的是,只有Model.update有效,而save永远不会有效,甚至不会触发回调。Mongoose:4.4.5MongoDB:3.0.8快速路线varmongoose=require('mongoose');mongoose.connect("mongodb://127.0.0.1:27017/db");vardb=mongoose.connection;db.on('error',console.error.bind(console,'connectionerror:'));db.once('open',function(callba

node.js - Mongoose 实例 .save() 不工作

我对Mongoose和MongoDb有疑问非常有趣的是,只有Model.update有效,而save永远不会有效,甚至不会触发回调。Mongoose:4.4.5MongoDB:3.0.8快速路线varmongoose=require('mongoose');mongoose.connect("mongodb://127.0.0.1:27017/db");vardb=mongoose.connection;db.on('error',console.error.bind(console,'connectionerror:'));db.once('open',function(callba

node.js - 如何在不覆盖当前数据的情况下更新 Mongoose 中的混合类型字段?

我有以下架构varmongoose=require('mongoose');varSchema=mongoose.Schema;varShopSchema=newSchema({name:Schema.Types.Mixed,country:{type:String,default:''},createdAt:{type:Date,default:Date.now},defaultLanguage:{type:String},account:{type:Schema.ObjectId,ref:'Account'},});mongoose.model('Shop',ShopSchema)

node.js - Mongoose 迁移

谁有一个迁移模块,他们用mongoose插件迁移mongodb数据?我目前正在使用“迁移”模块,它工作得很好,除了我需要在每次上/下时创建/销毁我的连接。I.E.//Setupmongoosevarmongoose=require('mongoose'),Role=require('../models/role'),User=require('../models/user');exports.up=function(next){//getabrandnewconnectionforthispatch.mongoose.connect('mongodb://localhost/saged

javascript - Mongoose 异步多次保存冲突

我在使用Node/Mongoose/Socket.io时遇到了一个很大的逻辑问题......假设我有一个服务器模型,它经常在我的应用程序中同时被调用,一些调用涉及更新模型中的数据。db.Server.findOne({_id:reference.server}).exec(function(error,server){catches.error(error);if(server!==null){server.anything="ahah";server.save(function(error){});}}有时,两个人会同时调用它,而第一个人会save()另一个人可能已经拥有findOn