var mgTest = require("../db/mongodb"); var videoTest_message = mgTest.model("videoTest_message"); /* video_message.find({username:"[email protected]"},"username -_id",function (err,rs) { console.log(rs); }); // 增加 videoTest_message.create({create_date:new Date(), username:"s3", host:"f3", storyId:"video3"}, function (err, doc) { if (err) { console.log(err); } else { console.log(doc); } }); // 移除 var removeDic = {username:"s1"}; videoTest_message.remove(removeDic, function (err, rs) { if (err) { console.error(err); } else { console.log("用户删除成功") } }); videoTest_message.find({username:"s1"}, function (err, rs) { if (err) { console.error(err); } else { console.log("该用户已被删除"); } }); //更新 videoTest_message.update({username:"s2"}, {$set:{username:"s22"}}, function (err, rs) { if (err) { console.error(err); } else { console.log("该用户已被更新"); } }); // 条件查询 "$lt"(小于),"$lte"(小于等于),"$gt"(大于),"$gte"(大于等于),"$ne"(不等于) videoTest_message.find({"username":{$lt:"s4"}}, function (err, rs) { if (err) { console.error(err); } else { console.log(rs); } }) //"$in"和$nin’ videoTest_message.find({"username":{$in:"s2"}}, function (err, rs) { if (err) { console.error(err); } else { console.log("包含:", rs); } }) // $or或$nor videoTest_message.find({$nor:[{username:"s22"},{storyId:"video3"}]}, function (err, rs) { if (err) { console.error(err); } else { console.log("或:", rs); } }) */ // $exists操作符,可用于判断某些关键字段是否存在来进行条件查询 videoTest_message.find({username:{$exists:true}}, function (err, rs) { if (err) { console.error(err); } else { console.log("$exists操作符:", rs); } })
[绍棠] MongoDB的增删改查
猜你喜欢
转载自blog.csdn.net/happyshaotang2/article/details/80451449
今日推荐
周排行