简体   繁体   English

如何在MongoDB集合上循环文档并与每个文档一起执行发布请求?

[英]How to loop a Documents on a MongoDB Collection and perform a post request with each one?

This is a one time task that I need to perform. 这是我需要执行的一项任务。 I'm new to mongo and programming but I think that I figured out a way of doing it but I need some help with details. 我是mongo和程序设计的新手,但我认为我想出了一种方法,但是在细节方面我需要一些帮助。

I want to loop over a whole collection and send each document as a POST request. 我想遍历整个集合并将每个文档作为POST请求发送。

col.find().sort('updatedAt', pymongo.ASCENDING).forEach( javascript function )

The above commenad should work. 以上建议应该起作用。 But my concerns are: 但我担心的是:

  1. Instead of js could I use python? 我可以使用python代替js吗? I haven't worked with js before. 我以前没有使用过js。
  2. If not, can I create post requests with javascript? 如果没有,我可以使用JavaScript创建发帖请求吗?
  3. Can I do it from the terminal in the mongo shell? 我可以在mongo shell的终端上执行此操作吗?

Thanks in advance! 提前致谢!

Javascript (ES5) Javascript(ES5)

db.collection.find({}).sort('updatedAt': 1).forEach(function(doc){postFunction(doc)});
  1. You can do this in Python. 您可以在Python中执行此操作。
  2. You can create a post request server-side with Node.js. 您可以使用Node.js在服务器端创建发布请求。
  3. You cannot send post requests with the mongo shell. 您无法使用mongo shell发送发帖请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在 MongoDB 中针对不同类型的文档进行单个查询,并将每种类型限制为一个集合中的特定数字? - Is there a way to make a single query in MongoDB for different types of documents and limit each type to a specific number in one collection? 在发布请求中使用mongodb插入多个文档 - Inserting multiple documents with mongodb in a post request 如何在ejs中显示集合中的文档数量? 用 mongodb - How to display the amount of documents in a collection in ejs? With mongodb 带后请求的每个循环的Angular - Angular For Each loop with post request MongoDB - 插入 2 个文档,每个文档都在另一个集合中,但共享 ObjectId - MongoDB - Insert 2 documents, each in another collection but share ObjectId 如何使用环回4执行发布请求 - How to perform a post request with loopback 4 在mongoDB中执行文本搜索,并为集合中的每个项目查找参考文档 - Perform a text search in mongoDB and find reference document for each item in the collection mongoDB 更新采集文件 - mongoDB update collection documents 如何在 For 循环中执行多个 axios POST 请求,每次循环迭代都有不同的主体数据? - How to perform multiple axios POST requests in a For Loop with different body data for each iteration of loop? 如何在 firebase firestore 中的集合文档之间循环? - How to loop between documents of a collection in firebase firestore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM