奥斯曼帝国不解决参考文献的问题

问题描述 投票:2回答:1

我的脚凳1.0.5设置中有两个模型。一个拥有联系信息,其中包括一组电子邮件文档,然后是电子邮件文档。我可以在文档中插入新的联系人以及电子邮件,也可以在联系人文档中插入新电子邮件的相应链接。

这是我的模特

const ottoman = require("ottoman")
ottoman.bucket = require("../app").bucket
var ContactModel = ottoman.model("Contact",{
    timestamp: {
        type: "Date",
        default: function() {return new Date()}
    },
    first_name : "string",
    last_name : "string",
    emails: [
        {
            ref:"Email"
        }
    ]}  )
var EmailModel = ottoman.model("Email",{
timestamp: {
    type: "Date",
    default: function() {return new Date()}
},
type : "string",
address : "string",
name: "string"
} )
module.exports = {
ContactModel : ContactModel,
EmailModel : EmailModel
}

现在获取联系人及其所有电子邮件,我使用此功能

app.get("/contacts/:id",  function(req, res){
model.ContactModel.getById(req.params.id,{load: ["emails"]}, function(error, contact){
if(error) {
res.status(400).json({ Success: false , Error: error, Message: ""})
      }
 res.status(200).json({ Success: true , Error: "", Message: "", Data : contact})
})
})

哪个还给我这个

{
"Success": true,
"Error": "",
"Message": "",
"Data": {
"timestamp": "2019-01-30T23:59:59.188Z",
"emails": [
    {
        "$ref": "Email",
        "$id": "3ec07ba0-aaec-4fd4-a207-c4272cef8d66"
    }
],
"_id": "0112f774-4b5d-4b73-b784-60fa9fa2f9ff",
"first_name": "Test",
"last_name": "User"
}
}

如果我去将联系人登录到控制台,我会得到这个

OttomanModel(`Contact`, loaded, key:Contact|0112f774-4b5d-4b73-b784-60fa9fa2f9ff, {
timestamp: 2019-01-30T23:59:59.188Z,
emails: [ OttomanModel(`Email`, loaded, key:Email|3ec07ba0-aaec-4fd4-a207-c4272cef8d66, {
 timestamp: 2019-01-31T00:36:01.264Z,
 _id: '3ec07ba0-aaec-4fd4-a207-c4272cef8d66',
 type: 'work',
 address: '[email protected]',
 name: 'Test Outlook',
 }),
 OttomanModel(`Email`, loaded, key:Email|93848b71-7696-4ef5-979d-05c19be9d593, {
 timestamp: 2019-01-31T04:12:40.603Z,
 _id: '93848b71-7696-4ef5-979d-05c19be9d593',
 type: 'work',
 address: '[email protected]',
 name: 'Test2 Outlook',
 }) ],
 _id: '0112f774-4b5d-4b73-b784-60fa9fa2f9ff',
 first_name: 'Test',
 last_name: 'User',
 })

这表明电子邮件已解决,但为什么它不显示在返回的json中。另一方面,如果我返回contact.emails,我会收到已解决的电子邮件。因此,我希望有人可以阐明我在这里缺少的内容

node.js couchbase couchbase-ottoman
1个回答
0
投票

我在沙发长椅论坛上问了类似的问题,我也找到了解决方案:(稍有不同,我的搜索结果是一个数组,而不是您所遇到的对象)

forum.couchbase.com

 app.get("/assets", (req, res) => {
    AssetModel.find({}, { load: ["assetModelId", "assetGroupId", "assetTypeId"] }, (err, results) => {
        if (err) return res.status(400).send("no asset found");
        const assets = [];
        results.map(asset => {
            assets.push({...asset});
        });
        res.status(200).send(assets)
    });
});
© www.soinside.com 2019 - 2024. All rights reserved.