MongoDB server side Javascript的介绍如下:

https://docs.mongodb.com/v3.0/core/server-side-javascript/#running-js-files-via-a-mongo-shell-instance-on-the-server

根据文档描述,可以直接传入一个Javascript对象来做查询,比如:

db.adminCommand({ 'getLog' : '<logname>' })

 

那么如果传入的是一个字符串,而不是一个JSON对象那?

该怎么样将这个字符串转换成JSON对象那?

方法有二:

  1. JSON.parse

JSON.parse('{ "name":"John", "age":30, "city":"New York"}');

 

  1. db.runCommand

db.runCommand('listDatabases');

相关文章:

  • 2022-01-03
  • 2022-02-26
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2021-06-13
  • 2021-11-28
  • 2022-02-06
  • 2021-06-14
  • 2022-12-23
  • 2021-11-19
相关资源
相似解决方案