草庐IT

node-keyboard

全部标签

node.js - 具有非空字段的 MongoDB/Mongoose 权重记录

我有一个MongoDB文档集合。我已经为特定字段分配了权重,但我需要将具有任何非空名称的记录加权到顶部。我不想按名称排序,我只是希望有名称的记录出现在没有名称的记录之前。示例模式:newSchema({slug:{type:String,index:{unique:true,dropDups:true}},name:String,body:{type:String,required:true}});示例索引:MySchema.index({name:'text',body:'text'},{name:'best_match_index',weights:{name:10,body:1}

node.js - 有没有办法在 mongodb(mongoose) 的单个查询中创建 "stored procedure"调用多查询

有没有办法在mongodb中创建“存储过程”?例如一个访问mongodb一次但实际上调用多个集合的查询?(使用mongoose调用mongodb)我知道mongodb有serversidejavascript.但不同的是,我不认为服务器端函数能够调用集合。例如,如果我有以下示例。1。示例一(关系集合)mycollection1.findOne({_id:id},function(err,result1){mycollection2.findOne({_id:result1.id},function(err,result2){mycollection3.findOne({_id:resu

node.js - 新安装的 MEAN.io 无法识别 MongoDB

我在安装MEAN.io后尝试grunt时遇到此错误:Error:failedtoconnectto[localhost:27017]**CouldnotconnecttoMongoDB.PleaseensuremongodisrunningandrestartMEANapp.**安装MEAN.io后是否需要执行额外步骤才能使MongoDB正常工作? 最佳答案 您可以按如下方式安装mongodb:$sudoapt-keyadv--keyserverkeyserver.ubuntu.com--recv7F0CEB10$echo'debh

node.js - Mongoose - useDb(name) 不允许超过 10 个并发请求

我们使用mongoose连接到MongoDB。最初创建了一个包含100个连接的池,并使用mongoose方法连接到其他数据库useDb下面是代码片段varurl=require("url");varconnectRoute=require('connect-route');varconnect=require('connect'),app=connect.createServer();varmongoose=require('mongoose');varconn=mongoose.createConnection('mongodb://localhost:10040/first',{s

node.js - Mongodb/ Mongoose 查询

一个User有一堆Essays,存储为一个ObjectIds数组。在CoffeeScript中,模式是:User=newSchemaessays:[Schema.Types.ObjectId]name:StringEssay=newSchemagrade:Numbertext:Stringauthor:Schema.Types.ObjectId如何在一个查询中获取所有不同用户,他们的最新论文是在最后一天写的,并且他们的最新论文的成绩在80到90之间?我有这个(在CoffeeScript中):req.mongoose.Essay.find(_id:$gt:#trickwhichcreat

node.js - 使用 Node 的 native mongodb 模块查询 Mongodb 中的 json 字段

我有一个mongo集合,其中已由使用MongoDBC#驱动程序的程序填充了文档。如果我运行查找client.connect('mongodb://127.0.0.1:27017/foo',function(err,db){varthings=db.collection('things');things.find({},['ThingId']).limit(1).toArray(function(err,docs){console.log(docs[0]);}}然后查看存储的内容然后我看到类似的内容{_id:1234235341234,ThingID:{_bsontype:'Binary

node.js - Mongoose 填充返回空

我的代码包含2个模型,内容和电影。电影引用了内容。在“电影”查询中,当我尝试填充内容时,返回null。内容模型'usestrict';varmongoose=require('mongoose'),validators=require('./validators'),Schema=mongoose.Schema;varcontentType=['M'];varContentSchema=newSchema({createdOn:{type:Date,default:Date.now},name:{type:String,required:true,unique:true,trim:tr

node.js - 如何在 Mongoose 中排序、选择和查询子文档

因此,我尝试对子文档进行排序,但也尝试对所有内容进行选择。似乎我不能使用常规查询,所以我尝试使用aggregatemongoose=require("mongoose");mongoose.connect("localhost:27017",function(err){mongoose.connection.db.dropDatabase();Story=mongoose.model("Story",{title:String,comments:[{author:String,content:String}]});sample=newStory({title:"Foobar",comm

node.js - 带有自己的 ObjectId 的 Mongoose 自引用抛出 : cast to ObjectId failed

我正在使用nodejs、Mongoose,我试图构建一个shema,其中包含通过父级对自身的引用。Parent应该是对DataType的引用。varDataTypeSchema=newSchema({_id:String,label:{type:String,required:true},comment:{type:String},url:{type:String,required:true},parent:{type:Schema.Types.ObjectId,ref:'DataType'},values:[]});varDataType=mongoose.model('DataTy

node.js - Mongoose 只得到一个字段的长度

这是我的Mongoose模式的示例:mongoose.model('Support',{createdBy:mongoose.Schema.Types.ObjectId,title:String,replies:{type:Array,default:[]}}回复数组可以包含多个对象,我对第一个查询不感兴趣,但我确实需要数组的长度。这个问题有Mongoose解决方案吗?目前我只是循环浏览每个文档。到目前为止我的代码:Support.find({},function(err,docs){if(err)throwerr;async.each(docs,function(doc,next){