Ottoman v2 query doubts and populate to select specific keys

Hi All,

We are using Ottoman v2 module for our application development, I have few doubts,

  1. How to unset the specific key at the document in Ottoman, previously i was used mongodb for unset function i know , ex: current document is
    { _id:“b0de5a04-7310-4865-842a-f47d231d1e3c”,
    name:“Store Users”,
    network:[4,5],
    created_at:“2021-03-10T10:55:05.647Z”
    }
    i want to remove network key.

  2. I need to select all the fields to except _type field, how to make this option
    await DepartmentModel.find({$or:[{change_status:1},{seq_status:1}]},{$all:’’,sort:{created_at:‘DESC’}});
    [{"_type":“Departments”,“name”:“Learning Algorithm”,“seq_status”:1,“sequence”:2,“change_status”:0,“created_at”:“2021-03-10T10:55:05.647Z”}]

  3. How to select specific populated fields at the Model
    await DepartmentModel.find({$or:[{change_status:1},{seq_status:1}]},{populate: ‘updated_by’,$all:’’,sort:{created_at:‘DESC’}});

above DepartmentModel query populate return below result,

{"_type":“Departments”,“name”:“Learning portal”,“seq_status”:1,“sequence”:2,“change_status”:0,“created_at”:“2021-03-10T10:55:05.647Z”,“id”:“2facd8b1-abb4-40cf-8e8e-e5cae5543157”,“status”:1,“updated_at”:“2021-03-10T10:57:40.180Z”,“updated_by”:{“uq_id”:“a-jd772892”,“name”:{“first”:“Rajasekar”,“last”:“Murugesan”},“claims":“XXXXXXXXXXXXXX-YYYYYYYYY-ZZZZZZZZZ”,“email”:"rajasekar@yahoo.com”,“id”:“b0de5a04-7310-4865-842a-f47d231d1e3c”,"_type":“Users”}}
but i want to select specific populated field as “uq_id” not all populated field at User Model,
Expected Result:
{"_type":“Departments”,“name”:“Learning portal”,“seq_status”:1,“sequence”:2,“change_status”:0,“created_at”:“2021-03-10T10:55:05.647Z”,“id”:“2facd8b1-abb4-40cf-8e8e-e5cae5543157”,“status”:1,“updated_at”:“2021-03-10T10:57:40.180Z”,“uq_id”:“a-jd772892”}

Thanks :),

  1. via Ottoman
    const doc = await Model.findById(“b0de5a04-7310-4865-842a-f47d231d1e3c”);
    delete doc.network;
    await doc.save();
  2. currently you cannot suppress the _type field, but we are looking to see how the select in project can do that.
  3. are you asking how to project certain fields ? or are you asking how does populate feature of Ottoman works and can I project certain fields ?
1 Like

Thanks for the update @AV25242

My third question is i can able to populated the collection & its return whole sub-object of users collections, i need to project single filed.

await DepartmentModel.find({$or:[{change_status:1},{seq_status:1}]},{populate: ‘updated_by’,$all:’’,sort:{created_at:‘DESC’}});

I have populated the updated_by field it refer Users collection,

Result:
{"_type":“Departments”,“name”:“Learning portal”,“id”:“2facd8b1-abb4-40cf-8e8e-e5cae5543157”,“status”:1,“updated_by”:{“ uq_id ”:“a-jd772892”,“name”:{“first”:“Rajasekar”,“last”:“Murugesan”},“claims":“XXXXXXXXXXXXXX-YYYYYYYYY-ZZZZZZZZZ”,“email”:“rajasekar@yahoo.com”,“id”:“b0de5a04-7310-4865-842a-f47d231d1e3c”,”_type":“Users”}}

Expected Result:
{"_type":“Departments”,“name”:“Learning portal”,“id”:“2facd8b1-abb4-40cf-8e8e-e5cae5543157”,“status”:1,“ uq_id ”:“a-jd772892”}

uq_id ”:“a-jd772892 - is arrive from Users collection, i want to project one fields only from Users document

@Rajasekar thanks selecting specific fields from a referenced object is not available yet but will add it to our roadmap

1 Like

@Rajasekar

. currently you cannot suppress the _type field, but we are looking to see how the select in project can do that.
This feature is now available can you test with latest Ottoman version ?
we fixed it with Projection should return back only the fields that are necessary · Issue #418 · couchbaselabs/node-ottoman · GitHub

1 Like