How does mongo export some information from an embedded array

  mongodb, question

Like this

 "_id": 1,
 "array": [
 {"name": "a", "price": "2","amount":1},
 {"name": "b", "price": "2","amount":2},
 {"name": "c", "price": "3","amount":4}

I just want to export the name attribute and price attribute. What should I do? It seems impossible to realize with mongoexport. do you have any good methods? Ask for advice

Mongo supports js scripts and can batch process and export data using javascript scripts:

#!  /usr/bin/env mongo
 db = db.getSiblingDB(db_name)
 // db.auth("user", "passwd");
 result = {};
 db.clt_name.find().forEach(function(r) {
 //here is the callback function, r is each record, is an object object, can traverse r.array, store the required attributes in result
 for (var key in result) {
 //Output in the format you want:
 print(key + "\t" + result[key])

Functions that can be used in the mongo environment are shown inWrite Scripts for the mongo Shell