Tag: upsert

使用Node.js插入或更新多个值到MySQL表中

我有一个表有一个复合主键(room_id,x_coord和y_coord)和另一个名为card_id的列。 我想插入几个logging到MySQL数据库。 我正在使用mysql库以及node.js的快速库。 如果logging不存在,我想插入由room_id,x_coord,y_coord和card_id组成的新logging。 另一方面,如果logging确实存在,我想将当前logging更新为新的card_id。 这里是我目前的代码的副本: //previously defined: room_id, x, y, and cards[] var i = 0; var db_values = []; for (var row = 0; row < y; row++){ for (var col = 0; col < x; col++){ card = cards[i]; //The following line may have a problem? db_values.push([room_id, col, row, card['id'], card['id']]); i++; […]

发出一个简单的mongo /修士findAndModify查询

只是一个说明,我对mongo来说还是比较新的,对于使用node / js来说更是显得非常新颖。 我试图编写一个查询来插入新文档或更新我的集合中已经存在的文档。 拟议的收集结构是: { _id: xxxxxxx, ip: "xxx.xxx.xxx.xxx:xxxxxx", date: "xx-xx-xx xxxx" } 请注意,我的意图是一个固定长度的int为_id而不是内部的ObjectId(这是可能的/被认为是不好的做法?)。 整数保证是唯一的,来自另一个来源。 var monk = require('monk'); var db = monk('localhost:27017/cgo_schedule'); var insertDocuments = function(db, match) { var db = db; var collection = db.get('cgo_schedule'); collection.findAndModify( { "query": { "_id": match.matchId }, "update": { "$set": { "ip": match.ip, "date": match.date }, "$setOnInsert": […]

我如何解释()在MongoDB中的upsert来查看是否使用索引?

当代码改变时,快速告诉我索引是否适合find()语句是( nodejs ) collection.find(query).explain(function(err, explaination) { console.log('MongoDebug: ' + explaination.cursor); }); 如果游标是BtreeCursortypes,则使用索引。 如何在使用insert()和upsert: true时检查这个问题upsert: true ?

如何在Mongoose的upsert操作中设置更新时间戳?

我想设置更新时间戳只用于在upsert操作中更新logging(并插入新logging的时间戳)。 self.model.update({Id: obj.Id}, obj, {upsert: true}, function(err){ if (err) { return; } //… }); 有没有办法处理这个? 有一个pre.save中间件我可以使用也许,但有什么办法告诉当前的操作是插入还是更新? 提前致谢!

如何自动更新Mongodb中的Upsert上的时间戳

如果我有一个密钥expires的架构, 每次文档更新时,我怎样才能得到该键的值来自动更新? 这可能会更复杂,但是,我upsert所以这个值将需要设置在初始insert ,然后更新每个upsert 。 所以,当文档被insert : { expires: *an hour from the insert* } 当它update (通过upsert ): { expires: *an hour from the update* } 如果MongoDB内置了这个function的话,我在使用Mongoose。如果Mongodb不支持它,也不会Mongoose,我只需要计算expires:并更新值,但是在Mongodb中自动完成这个操作会很好! 事实上,它不会真的需要insert ; 因为我可以检查expires为空,并从_id提取时间。 一如既往,任何帮助非常感谢!

Mongoose中的多文档上传

你好,这里是我的问题, var poolSchema = mongoose.Schema({ "topic_id": { type: Number, default: null, required: true }, "document_id": { type: String, default: null, required: true }, "project":{ type:String, default: false, required: true }, "createddate":{ type:Date, default : Date.now } }, { collection: "sorguHavuzu" }); 我有一个池文件的数组,每个项目具有不同的字段值,如下所示: var poolItems = [ {document_id :"FBIS3-50136" ,topic_id :"301" , project :"A1"}, {document_id :"LA040190-0178" […]

我可以$ addToSet和插入数组?

我正在使用Mongoose,而我的Schema如下所示: var WalletSchema = new Schema({ accounts: [String] }); 我的查询(Node.js)如下所示: Wallet.update {accounts: account}, {$addToSet: {accounts: account}}, {upsert: true}, (err, updWallet) -> asyncCb err 但是,我的数据库中没有任何wallets ,我预计这会上升。 它不是。 相反,它会返回一个错误: MongoError: Cannot apply $addToSet modifier to non-array 难道我做错了什么?

Mongsert的Upsert(node.js和mongodb)

我正在学习node.js和mongodb。 我在我的应用程序中使用mongoskin模块,但我似乎无法得到“upsert”function工作。 我读过github上的(非常不透明的)mongoskin指南。 以下是我迄今为止所尝试的: // this works. there's an insert then an update. The final "x" is "XX". db.collection("stuff").insert({a:"A"}, {x:"X"}); db.collection("stuff").update({a:"A"}, {x:"XX"}); // this does NOT work. I thought it would do an upsert, but nothing. db.collection("stuff").update({b:"B"}, {y:"YY"}, true); 我如何创build“更新或插入,如果不存在”function?

Node.js MongoDB Upsert更新

我正在写一个关键字分数的小应用程序。 因此,如果“贝鲁特”和“教育”进入,如果他们以前没有见过,我想创build一个mongo条目,并给他们1分。如果他们有,我想增加他们的分数一。 我试图用一个更新命令来做到这一点,但我想我可能做错了。 排名是代表数据库的对象 “关键”是关键字 rankingdb.update( {keyword:key}, {keyword:key, {$inc:{score:1}}}, {upsert:true, safe:false}, function(err, data) { if (err) { console.log(err); } else { console.log("score succeeded"); } } ); SyntaxError: Unexpected token { 你能不能创build一个全新的文件增量?