草庐IT

RETURN_VALUE

全部标签

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 - Doctrine/MongoDB : Use key-value pairs instead numeric array

我正在将DoctrineODM与MongoDB结合使用。我有一个这样的“产品模型”:namespaceCms\Model;/**@Document(collection="products")*/classProduct{/**@Id*/private$id;/**@String*/private$title;/**@String*/private$description;/**@Date*/private$createdAt;/**@EmbedMany(targetDocument="Cms\Model\ProductParam")*/private$params;/**@Embed

mongodb - 如何删除 mapReduce 中的 "value"?

我想知道是否可以删除map-reduce中的“value”键,以便最终结果直接包含值而不是在“value”键中。我希望仅使用命令(因此没有Javascript变量等)例如,map-reduce输出通常是[{"_id":0,"value":{"name":"Apple","sold":1234}},{"_id":1,"value":{"name":"Amazon","sold":5678}}]我希望它最终成为[{"_id":0,"name":"Apple","sold":1234},{"_id":1,"name":"Amazon","sold":5678}]我想这可以用findAndMo

c - 在迭代 bson 时访问 value.type

我正在尝试遵循libbsonAPI文档。但我好像弄错了什么。documentation声明你可以做:constbson_value_t*value;value=bson_iter_value(&iter);if(value.type==BSON_TYPE_INT32){printf("%d\n",value.value.v_int32);}但是当我尝试用它编译实际代码时,出现以下错误:example1.c:34:64:error:requestformember‘type’insomethingnotastructureorunion这里是实际的代码:#include#include#

node.js - Mongoose 通过 $set a value if NOT undefined 进行更新 (NodeJS)

检查未定义值的正确方法是什么?我想要做的是有一个PUT方法来更新那些不为空的字段。例如,如果我发送req.body.name='John'而没有发送req.body.job我希望我的请求只更改名称。部分代码:router.put('/:id',(req,res)=>{constquery={_id:req.params.id};constupdate={$set:{name:req.body.name,job:req.body.job}};User.findOneAndUpdate(query,update,(err,userUpdated)=>{if(err){console.log

javascript - "Cannot find global value ' Promise '"摩卡测试出错

以下内容与完整堆栈Node.js问题有关。它涉及Express、Mongoose和Mocha。我有一个Controller模块,它具有处理HTTP调用的功能。它基本上将Request和Response对象作为其参数。在其中,它将Form数据从Request对象中提取出来,并将数据存储在多个MongoDB实例中。为了完成多个数据存储,我们使用对Promise.all的调用。这是在异步函数中完成的。类似下面的内容asyncfunctionsaveData(data1:Data1Interface,data2:Data2Interface,res:Response){try{//Call3s

json - Mongoose 错误 : Cast to ObjectID failed for value on reading json for db seed

我有一个带有如下引用字段的模型方案:constUserSchema=newmongoose.Schema({//...uf:{type:mongoose.Schema.Types.ObjectId,ref:'UF',index:true},});我的测试数据库种子代码正在使用来自json文件的数据,如下所示:[{"_id":91283,"name":"Testuser","uf":124411923,"version":2}]在种子过程中,模型保存方法后,出现此错误:ValidationError:Uservalidationfailed:uf:CasttoObjectIDfailed

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=['

MongoDB - 获得 child 的最高值(value)

我正在尝试获取子值的最大值。如果我有两个这样的文件{"_id":ObjectId("5585b8359557d21f44e1d857"),"test":{"number":1,"number2":1}}{"_id":ObjectId("5585b8569557d21f44e1d858"),"test":{"number":2,"number2":1}}如何获得键“数字”的最大值? 最佳答案 使用点符号:db.testSOF.find().sort({'test.number':-1}).limit(1)