在邮递员中发布 objectId

posting objectId in postman

我正在尝试使用 postman

post 将此 json 转换为 API
{
"order" : [{ "mealId": 562b2649b2e70464f113c04d, "quantity": 4}],
"service_id" : 562b2649b2e70464f113c04d,
"dest" : "Allabama",
"active": false
}

但我一直收到此错误

SyntaxError: Unexpected token b
    at Object.parse (native)
    at parse (C:\nodeprojects\foodDelivery\node_modules\body-parser\lib\types\json.js:88:17)
    at C:\nodeprojects\foodDelivery\node_modules\body-parser\lib\read.js:108:18
    at invokeCallback (C:\nodeprojects\foodDelivery\node_modules\body-parser\node_modules\raw-body\index.js:262:16)
    at done (C:\nodeprojects\foodDelivery\node_modules\body-parser\node_modules\raw-body\index.js:251:7)
    at IncomingMessage.onEnd (C:\nodeprojects\foodDelivery\node_modules\body-parser\node_modules\raw-body\index.js:308:7)
    at IncomingMessage.emit (events.js:104:17)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)

它是一个带有猫鼬的 nodejs api。 这是 json 对象

的架构
var mongoose = require('mongoose');
var OrdersSchema = new mongoose.Schema({
order : [{ mealId: mongoose.Schema.Types.ObjectId, quantity: Number}],
service_id : mongoose.Schema.Types.ObjectId,
dest : String,
orderTime : {type:Date, default:Date.now},
completeTime : {type:Date, default:Date.now},
active: Boolean,
});

简而言之,问题是当我尝试传递 ObjectId 时,它在“562”后停止读取并将 'b' 视为非法字符。

您必须引用字符串:

{
"order" : [{ "mealId": "562b2649b2e70464f113c04d", "quantity": 4}],
"service_id" : "562b2649b2e70464f113c04d",
"dest" : "Allabama",
"active": false
}

接收 _id 对象作为字符串而不是 ObjectId, 当你得到这个 id create new mongo.driver ObjectId

 public async Task<IHttpActionResult> PostExample(string idinstring)
 {
         ObjectId d=new ObjectId(idinstring);
  }