Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MongoDB

Lấy đầu ra của script MongoDB shell?

Bạn có thể sử dụng printjson() hoặc print() để lấy đầu ra của script MongoDB shell. Tạo một mảng đối tượng:

> var studentDetails=[{"StudentName":"John","StudentAge":21}, {"StudentName":"Carol","StudentAge":24},{"StudentName":"David","StudentAge":25}];

Sử dụng printjson() để hiển thị đầu ra:

> printjson(studentDetails);

Kết quả:

[
  { "StudentName" : "John", "StudentAge" : 21 },
  { "StudentName" : "Carol", "StudentAge" : 24 },
  { "StudentName" : "David", "StudentAge" : 25 }
]