[英]What's the best practice to store events with NodeJs and MongoDB
I need to store all the database interactions(CRUD) in a collection, I research about but I didn't find a best way to do this. 我研究了所有数据库交互(CRUD)的集合,但我没有找到最佳的方法。
My app works with mongoose and I can use the pre/post hooks for insert this information in a collection. 我的应用程序可以使用猫鼬,并且可以使用前/后钩子将此信息插入集合中。 Mongoose Midleware
猫鼬Midleware
Are there are others options for implement this? 还有其他实现此目的的选择吗?
1)So technically if you're asking for catching the CRUD operations performed on mongodb ,Mongoose is an ORM(Object Relational Mapper) which does the job for you, but just in the conventional sort of Relational DB's like MSSQL Server ,the only hooks available to track the firing queries or DB transactions were triggers.Similarly,you can use triggers and listeners in mongodb ,check this package https://www.npmjs.com/package/mongo-triggers 1)因此从技术上讲,如果您要捕获在mongodb上执行的CRUD操作,Mongoose是一个ORM(对象关系映射器),可以为您完成工作,但仅在常规关系数据库(如MSSQL Server)中,唯一的钩子类似地,您可以在mongodb中使用触发器和侦听器,请检查此程序包https://www.npmjs.com/package/mongo-triggers
2) You can use something what mongo itself provides called as Tailable Cursors see the documentation https://docs.mongodb.com/manual/core/tailable-cursors/ 2)您可以使用mongo本身提供的称为“可拖尾光标”的功能,请参阅文档https://docs.mongodb.com/manual/core/tailable-cursors/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.