[mongo2js] Bug: field level operators must support arrays
See original GitHub issueI’m currently testing mongo2js and noticed that gt and gt doesn’t works on nested arrays. I’m using sift to compare results.
const sift = require("sift");
const { filter } = require("@ucast/mongo2js");
const query = { "foo.bar.baz": { $lt: 0 } };
const uQuery = filter(query);
const siftQuery = sift(query);
const data = { foo: [{ bar: [{ baz: 1 }] }] };
const uResult = uQuery(data);
// true
// value returned by "getField" : [ 1 ] and comapred against query value "1"
const siftResult = siftQuery(data);
// false
This is because in @ucast/js, in this case, the comparison interpreters like lt compare array of values against a single value. This is due to the getField function that returns an array of value.
I thought about a solution and because the actual value could be an array, we would need to know if values have been aggregated into an array or if the value is an array. But there might be a simpler solution.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Chapter-4 Lab 2: Array Operators - M001: MongoDB Basics
The first slice is fine, but $all is not a valid expression operator. We could re-write the query as: db.coll.find({ "property_type":"House", " ...
Read more >import does not work on json arrays files. #433 - GitHub
I am getting the same error: "MongoError: operation passed in cannot be an Array" i used the modification and doesnt help at all, ......
Read more >Im getting an "Unknown top level operator error" in MongoDB
The data is in an array in the collection called sales and the array's name is items and I then want to match...
Read more >@ucast/mongo2js - npm
Start using @ucast/mongo2js in your project by running `npm i ... In order to implement a custom operator, you need to create a...
Read more >MongoDB - Array Update Operators - YouTube
In this video, shows you different operators on update an array value.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fixed in @ucast/js@2.1.1
run
npm update
and it will fetch new deps for@ucast/mongo2js
That’s right, it’s there.
What I saw is this, but it’s only mentioning that it doesn’t works with objects.
So I think it’s safe to do it this way.