草庐IT

Collection-hooks

全部标签

node.js - 异步 : Combining two mongodb collection using Async. forEach

我是MEAN堆栈的新手,我正在尝试学习异步。我正在尝试使用async合并来自mongodb的两个集合并应用了这个iterateoveracollection,performanasynctaskforeachitem,我正在尝试学习完成这些简单任务的最简单有效的方法,以便它易于理解。varOrderSchema=newmongoose.Schema({menu_id:{type:mongoose.Schema.Types.ObjectId,ref:'Foods'},menu_name:{type:String,required:false},customer_id:{type:Stri

mongodb - 在 MongoShell : Not able to connect to my collection, db.collection_name 返回 NaN

我使用的是MongoDBEnterprise,MongoDBshell版本:3.2.5我有一个db=mydb和一个collections=['events','events__2015-12-01','events__2015-11-01']我有一个python/pymongo脚本,我可以在其中连接到每个文档,但在mongoshell中我无法连接到过时的集合?换句话说mongodb>usemydbswitchedtodbmydbmongodb>db.eventmydb/eventmongodb>db.event__2015-12-01NaNmongodb>db.event__2015-

node.js - TypeError : db. collection.createIndex 不是快速项目搜索功能中的函数

使用下面的代码我得到错误TypeError:db.collection.createIndexisnotafunction,我想用它来实现来自这个站点的搜索功能:https://docs.mongodb.com/manual/text-search/也许有其他方法可以搜索MongoDB?app.post('/search',function(req,res){varresults=[];mongodb.MongoClient.connect(url,function(err,db){db.collection.createIndex({Name:"text",Code:"text"})

javascript - 要更新 MongoDB 文档中的单个字段,最好的方法是什么? feathersjs 中的更新或补丁 Hook

我尝试在单个字段中更新mongodb文档,我怀疑我想使用哪种方法使用补丁或更新使用羽毛框架,请举例说明我们如何做到这一点。const{authenticate}=require('feathers-authentication').hooks;module.exports={before:{all:[authenticate('jwt')],find:[],get:[],create:[],update:[],patch:[],remove:[]},after:{all:[],find:[],get:[],create:[],update:[],patch:[],remove:[]},

node.js - mongodb nodejs db.collection 不是函数

这是我的FollowerModel类(在ES6中)代表我的MongoDB的follower集合importmongofrom'mongodb';classFollowerModel{constructor(db,logger){this._db=db;this._logger=logger;}asynccreate(data){try{data._id=mongo.ObjectID().toString();returnawaitthis._db.collection('follower').insertOne(data);}catch(error){returnPromise.rej

node.js - 如何在 mongoose pre updateOne Hook 中获取文档 _id?

我为我的模型做了updateOne并且在我的方案上有preupdateOneHook,如下所示:constschema=newmongoose.Schema({name:{type:String}});schema.pre('updateOne',asyncfunction(){fs.writeFileSync('./query.json',stringify(this,null,2),'utf-8');});constModel=mongoose.model('Model',schema);letres=awaitModel.create({name:"I'llbeupdatedso

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

python - Flask-PyMongo : how come "self._Collection__database"?

在Flask-PyMongo中,他们使用self._Collection__database来表示这个Collection对象所属的数据库对象:classCollection(collection.Collection):"""Customsub-classof:class:`pymongo.collection.Collection`whichaddsFlask-specifichelpermethods."""def__getattr__(self,name):attr=super(Collection,self).__getattr__(name)ifisinstance(att

mongodb - 如何在传递给模板之前格式化 Collection.find 的结果

HTML:{{#eachplayers}}{{>player}}{{/each}}{{name}}{{score}}{{joindate}}JS:Players=newMeteor.Collection("players");if(Meteor.isClient){Template.players=function(){returnPlayers.find();};}if(Meteor.isServer){Meteor.startup(function(){if(Players.find().count()===0){varnames=["AdaLovelace","GraceHopp

java - 未授权使用 eclipse 在 mongodb 上查询 databasename.collection

我为DBpurp赋予的角色是UserAdmin,我使用mongod--auth--dbpathc:\mongodb\data\db运行服务器。首先我在eclipse中做了一个java文件来连接数据库,它工作正常。在我创建并在eclipse中运行以下文件后:try{MongoClientmongoClient=newMongoClient("localhost",27017);DBdb=mongoClient.getDB("purplista");booleanauth=db.authenticate("purp","123".toCharArray());System.out.prin