Ottoman v2 logical where in operations for array fields

Hi All,

I have below schema format from Application model,

{"_type":“Application”,“id”:“a92846f2-dac2-414e-ae59-ff570f9c1642”,“name”:“MyAccount”,“app_owner”:“Mark”,“app_url”:“https://www.couchbase.com/",“change_status”:4,“dept_id”:“544611b0-56d2-4345-a43a-5ee39c8620dc”,“device_visibility”:[1,2,3,4,5,6],“icon_url”:“IMG_20210309_142738.png”,“launchers”:[1,2,3],“network_visibility”:[2,3,7],“created_at”:"2021-03-09T14:01:27.672Z”}

I want to be execute below conditions ,
device_visibility should be - 2, network_visibility - 3 and launchers - 2

is it possible to run Ottoman model or we can try with Query Builder

Thanks :slight_smile:

@Rajasekar not clear with your question, are you asking you want to find this data ? Also is it possible that you post Ottoman questions on Ottoman Github please? This way you will get many other contributors who can answer your questions :slight_smile:

I stored below format of document array ,

{“device_visibility”:[1,2,3,4,5,6],“launchers”:[1,2,3],“network_visibility”:[1,2,3]}

we categorize device visibility as 1 - mobile, 2- desktop, 3- ios…,
network_visibility as 1 - internet, 2- corporate vpn… etc

i need to check above document device_visibility value is 1 (mobile) is exist, network field 2 (corporate vpn) is exist from the array & etc…

I hope you, you understand the my doubt. Next time i will raise Ottoman github

Thanks,

@Rajasekar you can use model find or you can also use query builder. Model.find uses N1QL behind the scenes.

Hi @AV25242 i have tried, but not working

This key values was stored “device_visibility”:[1,2,3,4,5,6]

applicationlist = await ApplicationModel.find({$and:[{status:1},{$in: { search_expr: ‘device_visibility’, target_expr: 2 }}]},{sort:{name:‘ASC’}});

@Rajasekar see if this helps Ottoman V2. Find document using value from array

Hi @AV25242 , above example is not suitable for me, kindly find my schema

Schema:
var ApplicationModel = ottomanConnection.model(‘Application’,{
name:String,
dept_id:{type:String,ref:‘Departments’},
app_url: String,
icon_url: String,
status: Number
change_status : {type:Number,default:0},
device_visibility: [Number],
network_visibility: [Number],
launchers: [Number],
created_at: Date,
updated_at: Date,
updated_by: {type:String,ref:‘Users’}
});

Document:
{
“_type”: “Application”,
“id”: “a92846f2-dac2-414e-ae59-ff570f9c1642”,
“name”: “MyAccount”,
“app_owner”: “Mark”,
“app_url”: “https://www.couchbase.com",
“change_status”:4,
“dept_id”:“544611b0-56d2-4345-a43a-5ee39c8620dc”,
“device_visibility”:[1,2,3,4,5,6],
“launchers”:[1,2,3],
“network_visibility”:[2,3,7],
“created_at”:"2021-03-09T14: 01: 27.672Z”
}

my input value is device_visibility 3 and network_visibility 4, so we want to match value exist on device_visibility & network_visibility array fields.

Thanks,

Hello @Rajasekar that is correct, the example doesn’t depict your case but that definitely showcases how to use the $in clause

const filter = {
$in: { search_expr: ‘device_visibility’, target_expr: [2] }
}

In your case the above should help, what you were missing I think is the square brackets
Let me know if thats the case or am I missing something

Thanks @AV25242 i understand the $in clause logic :slight_smile:

I tried above option with square brackets, still not working, any thoughts? or anything need to change …

Thanks,

@Rajasekar I think you are right

one way is using Query directly i.e ottoman.query(query)

SELECT d.*
FROM `bucket-name` AS d
UNNEST d.device_visibility AS dv 
UNNEST d.launchers AS la
WHERE dv IN [2]  and la in [20]
LIMIT 10;

Super @AV25242 thanks, i get correct result on above query. I have tried ANY & SATISFIES query, thats one also working fine.

SELECT id,name
FROM bucket
WHERE _type=‘Application’
AND ANY p IN device_visibility SATISFIES p IN [1] END

Which approach is best UNNEST or ANY & SATISFIES? Why we cant achieve this operation in ottoman model itself.

Thanks

1 Like

@Rajasekar any satisfies probably

Also have created a ticket to support this in future within ottoman

1 Like

Many thanks @AV25242 & thanks for your effort. I hopefully expect some more features covered in next release.

@Rajasekar that is correct, most likely in the next alpha release we would try to loop in as many features as we can. stay tuned !

On a side note can you please discuss your use case ? and help me with some of the answers.

What is you project all about ? (greenfield or brownfield)
What is your environment and development stack. ( Couchbase server version, number of nodes, frontend, middleware etc)
Where does Ottoman fit ? Benefits you see using Ottoman.

Hello @AV25242
What is you project all about ? (greenfield or brownfield)
Our project is brownfield category based. We started from scratch, its already running in PHP & Oracle tech stacks. Now we upgarde the tech stacks. We handle the 50K + applications in our projects, those applications to be dispalying on different environment based. such as Networks, Desktop, Mobile and user role… etc (use case)

What is your environment and development stack. ( Couchbase server version, number of nodes, frontend, middleware etc)
Initially using windows 10 laptop for development environment, you know we facing issue like “Error: cluster object was closed” on most of time. My colleague also tried windows 10 laptop, he also facing same issue. So we directly working our Windows Server 2016 pre-production server.
Production purpose planned for CentOS. Currently using couchbase 6.5 version & created 8 nodes (4 - data, 2- index, 2-query) - this is for both develoment & production
Tech stack as Nodejs, Express JS, React JS, Material UI

Where does Ottoman fit ? Benefits you see using Ottoman.
We started worked Ottoman 1.0.6 version on year back i think 2019 Dec, that version is callback model based & not support most of query’s in 1.0 version, so we maintanined 2 connections 1 is ottoman, 2 plain node sdk. Actually we worked 2 months using old version, so didn’t completed the development. After we moving with different works.

Now we have time to back visit latest Ottoman version 2.0 and upgrade the our frontend/backend tech stacks. I am from MongoDB database background, i used Mongoose ODM. So we expect to cover 80 % of function on Ottoman.

Benefits:

  • Good to Perform CRUD operations and indexing.
  • Most of the CouchBase operations covered in the v2.0 ODM
  • We get quick response from our community for query/issue related doubts, mostly you :slight_smile:

Feedbacks:
Please check why “Error: cluster object was closed” errors happening on windows 10 machines.
Need to add additional examples and descriptions on https://v2.ottomanjs.com/

Thank you @Rajasekar on the response, you are a great partner to work with as well.

Will look at your feedbacks to improve Ottoman, once past major feature list
On your use case

some followup questions, again feel free to respond only if you are ok/comfortable.
50k + applications sounds like a huge project :slight_smile:

Who are your target customers?
How many customers do you serve today (tentatively)
What does your application provide, like what is your application feature and which domain (Healthcare, finance) do they serve ?
What problem do they solve ?

You can respond to me privately as well. Thanks @Rajasekar

@Rajasekar the issue that addresses this concern should be available for you to test. Please get the latest Ottoman release.

1 Like

Thanks a lot @AV25242 , i will test it.