【发布时间】:2015-11-28 21:38:37
【问题描述】:
我在使用 Restivus 时遇到了一个简单的初学者问题。
在我的 app.js 中我已经声明:
Players = new Mongo.Collection("players");
及以后:
if (Meteor.isServer) {
// Global configuration
Api = new Restivus({
useDefaultAuth: true,
prettyJson: true
});
// Generates: GET/POST on /api/v1/players, and GET/PUT/DELETE on /api/v1/players/:id
// for Meteor.users collection (works on any Mongo collection)
Api.addCollection(Players);
// That's it! Many more options are available if needed...
}
然后我启动“meteor mongo”
meteor:PRIMARY> db.players.insert({username:"Kalle", location:"Home"})
WriteResult({ "nInserted" : 1 })
meteor:PRIMARY> db.players.insert({username:"Pelle", location:"Away"})
WriteResult({ "nInserted" : 1 })
meteor:PRIMARY> db.players.find({});
{ "_id" : ObjectId("56598d83846a7b53e8a1176b"), "username" : "Kalle","location" : "Home" }
{ "_id" : ObjectId("56598d8c846a7b53e8a1176c"), "username" : "Pelle", "location" : "Away" }
当我使用 CURL 进行尝试时,我得到:
curl -X GET http://localhost:3000/api/players
{
"status": "success",
"data": [
{
"_id": {
"_str": "56598d83846a7b53e8a1176b"
},
"username": "Kalle",
"location": "Home"
},
{
"_id": {
"_str": "56598d8c846a7b53e8a1176c"
},
"username": "Pelle",
"location": "Away"
}
]
但是当我试图找到一个特定的文档时:
curl -X GET http://localhost:3000/api/players/56598d83846a7b53e8a1176b
{
"status": "fail",
"message": "Item not found"
}
为什么找不到文档,怎么回事:
"_id": {
"_str": "56598d83846a7b53e8a1176b"
}
【问题讨论】: