Different results between console.log() .send()

Hi,

I’m currently using the following versions:

Couchbase Community Edition: 6.0.0
Couchbase Node SDK: “couchbase”: “2.6.7”,
Ottoman ODM : “ottoman”: “1.0.6”
Node : v10.15.3

here is the connection to Couchbase with Ottoman:
const Couchbase = require(“couchbase”);

const Ottoman = require("ottoman");
const Express = require("express");
const dotenv = require("dotenv");
const app = Express();

dotenv.config();


const cluster = new Couchbase.Cluster(process.env.DB_IP);

cluster.authenticate(process.env.DB_USERNAME, process.env.DB_PASS);

const bucket = cluster.openBucket('itstudio', function() {

console.log("Connected to the DB")

});

Ottoman.store = new Ottoman.CbStoreAdapter(bucket, Couchbase);

...

const server = app.listen(4001, function() {

console.log("Connected on port 4001...");

});

Here is the model :

 const Ottoman = require("ottoman");

const AssetModel = Ottoman.model("Asset", {
    assetTypeId: { ref: "AssetType" },
    assetModelId: { ref: "AssetModel" },
    assetGroupId: { ref: "AssetGroup" },
    connection: { type: "boolean" },
    operation: { type: "string" },
    name: { type: "string" },
    description: { type: "string" },
    location: { type: "string" },
    activeStatus: { type: "boolean" },
    archiveStatus: { type: "string" },
    runNum: { type: "string" }
});

const AssetTypeModel = Ottoman.model("AssetType", {
    assetType: { type: "string" },
    description: { type: "string" },
    activeStatus: { type: "string" },
    archiveStatus: { type: "string" },
    runNum: { type: "string" }
});

const AssetGroupModel = Ottoman.model("AssetGroup", {
    groupName: { type: "string" },
    description: { type: "string" },
    activeStatus: { type: "string" },
    archiveStatus: { type: "string" },
    runNum: { type: "string" }
});
const AssetModelModel = Ottoman.model("AssetModel", {
    modelName: { type: "string" },
    description: { type: "string" },
    activeStatus: { type: "string" },
    archiveStatus: { type: "string" },
    runNum: { type: "string" }
});

module.exports.AssetModel = AssetModel;
module.exports.AssetTypeModel = AssetTypeModel;
module.exports.AssetGroupModel = AssetGroupModel;
module.exports.AssetModelModel = AssetModelModel;

and here is the route to find all the existing assets:

const { AssetModel, AssetTypeModel, AssetGroupModel, AssetModelModel } = require("../models/assetsModel");

const router = function (app) {

   ...
    //Get all the Assets for the Dashboard Simple Table 
    app.get("/assets", (req, res) => {
        AssetModel.find({}, { load:  [ "assetModelId", "assetGroupId", "assetTypeId" ] }, (err, assets) => {
            if(err) return res.status(400).send("no asset found");
            console.log(assets) // <-- this 
            res.status(200).send(assets) // <-- and this 
        });
    });

};

module.exports = router;

and here comes my question:
when I console.log the assets (marked with <-- arrow) everything is fine, I can see all the details of the documents also including subdocuments like that:

 OttomanModel(`Asset`, loaded, key:Asset|fb860e6d-f968-4a38-bc3b-df3bbc097cb7, {
  _id: 'fb860e6d-f968-4a38-bc3b-df3bbc097cb7',
  connection: false,
  operation: 'Idle',
  name: 'MyRobot004',
  description: 'QWERTZUIOPASDFGHdfafadsfaf',
  location: 'Arc Welding Cell 01',
  activeStatus: true,
  archiveStatus: false,
  assetTypeId: OttomanModel(`AssetType`, loaded, key:AssetType|8c4636eb-022f-49e9-85d1-2a48ae87066f, {
    _id: '8c4636eb-022f-49e9-85d1-2a48ae87066f',
    assetType: 'Device',
    description: 'qwertz',
    activeStatus: true,
    archiveStatus: false,
  }),
  assetGroupId: OttomanModel(`AssetGroup`, loaded, key:AssetGroup|9f5512cd-21cb-4aab-ba8c-ad02e3fb516d, {
    _id: '9f5512cd-21cb-4aab-ba8c-ad02e3fb516d',
    groupName: 'Arc Welding',
    description: 'qwert',
    activeStatus: true,
    archiveStatus: false,
  }),
  assetModelId: OttomanModel(`AssetModel`, loaded, key:AssetModel|9b590724-bd5b-4cde-a8ad-d82b773a7d6f, {
    _id: '9b590724-bd5b-4cde-a8ad-d82b773a7d6f',
    modelName: 'Arc Mate 100iD',
    description: 'qwertz',
    activeStatus: true,
    archiveStatus: false,
  }),
})

and when I’m getting the results in postman or frontend application the subdocument details are no longer there just their ref and id like so:

{
        "_id": "fb860e6d-f968-4a38-bc3b-df3bbc097cb7",
        "connection": false,
        "operation": "Idle",
        "name": "MyRobot004",
        "description": "QWERTZUIOPASDFGHdfafadsfaf",
        "location": "Arc Welding Cell 01",
        "activeStatus": true,
        "archiveStatus": false,
        "assetTypeId": {
            "$ref": "AssetType",
            "$id": "8c4636eb-022f-49e9-85d1-2a48ae87066f"
        },
        "assetGroupId": {
            "$ref": "AssetGroup",
            "$id": "9f5512cd-21cb-4aab-ba8c-ad02e3fb516d"
        },
        "assetModelId": {
            "$ref": "AssetModel",
            "$id": "9b590724-bd5b-4cde-a8ad-d82b773a7d6f"
        }
    }

So how can I also get all the details of the subdocuments?

If I downgrade Ottoman version (also Couchbase SDK) to 1.0.4 it works fine but with 1.0.5 and 1.0.6 it doesn’t go.

{
    "_id": "fb860e6d-f968-4a38-bc3b-df3bbc097cb7",
    "connection": false,
    "operation": "Idle",
    "name": "MyRobot004",
    "description": "QWERTZUIOPASDFGHdfafadsfaf",
    "location": "Arc Welding Cell 01",
    "activeStatus": true,
    "archiveStatus": false,
    "assetTypeId": {
        "_id": "8c4636eb-022f-49e9-85d1-2a48ae87066f",
        "assetType": "Device",
        "description": "qwertz",
        "activeStatus": true,
        "archiveStatus": false
    },
    "assetGroupId": {
        "_id": "9f5512cd-21cb-4aab-ba8c-ad02e3fb516d",
        "groupName": "Arc Welding",
        "description": "qwert",
        "activeStatus": true,
        "archiveStatus": false
    },
    "assetModelId": {
        "_id": "9b590724-bd5b-4cde-a8ad-d82b773a7d6f",
        "modelName": "Arc Mate 100iD",
        "description": "qwertz",
        "activeStatus": true,
        "archiveStatus": false
    }
}

note: all the data are dummy :wink:

Hey @Manooo,

There was a change between 1.0.4 and 1.0.5 which switched to providing refid’s for sub-documents, and there is not currently a way to resolve that without manually generating JSON for the specific fields which are being referenced. I’m going to look into a long-term solution as I had to work-around it myself recently.

Cheers, Brett

Hi @brett19,

Thanks for the quick reply I appreciate that!
So what do you suggest:
Should I use 1.0.4 version or use 1.0.5-6 and generate JSON manually? What are the benefits of the 1.0.5-6 version?
Where can I find releasenotes or changelog?
BR, Mano

Hi @brett19,

We find out a solution to this problem, it is more simple than I thought.
The Solution is … , I mean “Spread Operator”.
Use it this way:

 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)
    });
});

I posted it here for everyone who has the same problem.

Regards, Mano