草庐IT

T_RETURN

全部标签

node.js - 蒙戈/ express : How to return all documents in collection if no query params are passed?

如果没有传递查询参数,我将尝试从我的Mongo集合中返回所有文档。目前我有3个可选的查询参数可以由用户传递。localhost:3000/api/projects//shouldreturnallprojects.Currentlythisisreturning[]localhost:3000/api/projects?id=1//shouldreturnprojectswithidof"1".Workingproperly.localhost:3000/api/projects?name=myproject//shouldreturnprojectswithnameof"myproj

node.js - Nodejs 和 MongoDB : Unable to return value from a function

varconfig=require('config.json');varmongo=require('mongoskin');vardb=mongo.db(config.connectionString,{native_parser:true});module.exports.getNextSequence=function(name){vartemp;db.collection("counters").findAndModify({_id:name},//query[],//representsasortorderifmultiplematches{$inc:{seq:1}},//u

mongodb - 蒙戈 : Return specific fields from an array slice

我想从Mongo中的数组返回特定​​字段,但遇到了问题。假设我们有这样一个文档:{"student":"Bob","report_cards":[{"Year":2016,"English":"B","Math":"A"},{"Year":2015,"English":"B","Math":"A"}]}我想返回以下内容:{"Student":"Bob",{"English":"B"}}基本上,我只需要报告卡数组中的第一个元素,并且只返回英文字段。我知道它是周围的东西:db.collection.find({},{"Student":1,"report_cards":{$slice:1}

MongoDB/珀尔 : find_one doesn't return data after unrelated code

mongodb是v4.0.5Perl是5.26.3MongoDBPerl驱动程序是2.0.3这个Data::Dumper输出显示是什么让我发疯INFO-$VAR1=['2753692498269306891',{'conf'=>{'param'=>'argument'},'id'=>'275369249826930689','lastmsg'=>'604195211232139552','_id'=>bless({'oid'=>']:\',&�h�GeR'},'BSON::OID')}];352832438449209345275369249826930689INFO-$VAR1=['

node.js - MongoDB + Node.js : delete multiple documents and return them

我正在使用以下代码一次删除多个文档:db.collection('testcollection').deleteMany({id:{$in:['1','2','3']}},function(error,response){//...});有没有办法一次性删除并返回所有被删除的文档?注意:我正在寻找多个删除和多个返回,这与这个问题不同:HowtogetremoveddocumentinMongoDB? 最佳答案 不幸的是,deleteMany()仅传递error和deleteWriteOpResult到你的回调,所以没有实际的文件被传

php - PHP Mongo 问题列表 : What does _construct return when replicaSet is true?

在PHPmanual,它有这个例子:true));//youonlyneedtopassasingleseed,thedriverwillderivethefulllistand//findthemasterfromthisseed$m2=newMongo("mongodb://ny1.example.com",array("replicaSet"=>true));?>但是,$m1返回什么?如果我想找出主节点并进行复制,以便主节点负责写入,而其中一个副本负责读取连接,那么我应该找出并应该做什么的最佳方式是什么?我能否拥有不同于每个副本的持久值?或者他们必须共享相同的连接channel?

mongodb - Mongo 通过正则表达式查找 : return only matching string

我的应用程序有以下堆栈:Ruby上的Sinatra->MongoMapper->MongoDB应用程序将多个条目放入数据库中。为了交叉链接到其他页面,我添加了某种语法。例如:Coffeeisablack,caffeinatedliquidmadefrombeans.{Tea}ismadefromleaves.Bothdrinksaresometimesenjoyedwith{milk}在此示例中,{Tea}将链接到另一个关于茶的数据库条目。我正在尝试查询我的mongoDB关于所有“链接的术语”。通常在ruby​​中我会做这样的事情:/{([a-zA-Z0-9])+}/其中()将返回匹配

arrays - 蒙戈聚合 : return total average of array values

我在mongodb中有这些数据{"name":"FooBar","__v":0,"user_rating":[{"date":"2017-06-02T16:19:32.002Z","user_rating":5,},{"date":"2017-06-02T16:19:46.803Z","user_rating":3,},{"date":"2017-06-02T16:20:01.244Z","user_rating":5,},{"date":"2017-06-02T16:15:54.673Z","user_rating":3,},{"date":"2017-06-02T16:53:42.

javascript - 需要在async find操作里面修改json和return

我需要遍历对象ID列表,找到一个用户,然后修改json对象并返回它。我研究了bluebird,但下面的代码没有按照我的意愿执行。返回后好像修改了json对象。我尝试返回user["test"]="lol"但它只返回“test”的值,而我需要整个更新的json。Promise.map(['5781635026d6fad4486d81e9','578296e31029e27b4ea53e9d'],function(i){returnUser.findOneAsync({_id:i}).then(function(user){user["test"]="lol";returnuser;});

javascript - 尝试从集合中获取随机游标 - 错误 : Publish function can only return a Cursor or an array of Cursors

我正在尝试从一组问题中随机发布一个问题。但是我收到一条错误消息:错误:发布函数只能返回一个游标或一个游标数组。如何更改下面的出版物以便输出一个随机问题?Publications.jsMeteor.publish('randomQuestions',function(){varrandomInRange=function(min,max){varrandom=Math.floor(Math.random()*(max-min+1))+min;returnrandom;};varq=Questions.find().fetch();varcount=q.length;vari=random