Comments (10)
Running this file on node.js reproduces the error. You need to have set "type": "module"
in the package.json.
import { useOperators, OperatorType } from 'mingo/core';
import { Query } from 'mingo/query';
import { $project } from 'mingo/operators/pipeline/project';
import { $sort } from 'mingo/operators/pipeline/sort';
import { $and } from 'mingo/operators/expression/boolean/and';
import { $not } from 'mingo/operators/expression/boolean/not';
import { $or } from 'mingo/operators/expression/boolean/or';
import { $nor } from 'mingo/operators/query/logical/nor';
import { $eq } from 'mingo/operators/expression/comparison/eq';
import { $ne } from 'mingo/operators/expression/comparison/ne';
import { $gt } from 'mingo/operators/expression/comparison/gt';
import { $gte } from 'mingo/operators/expression/comparison/gte';
import { $lt } from 'mingo/operators/expression/comparison/lt';
import { $lte } from 'mingo/operators/expression/comparison/lte';
import { $regex } from 'mingo/operators/query/evaluation/regex';
import { $mod } from 'mingo/operators/query/evaluation/mod';
import { $elemMatch } from 'mingo/operators/projection/elemMatch';
import { $exists } from 'mingo/operators/query/element/exists';
import { $nin } from 'mingo/operators/query/comparison/nin';
import { $in } from 'mingo/operators/query/comparison/in';
import { $size } from 'mingo/operators/expression/array/size';
import { $type } from 'mingo/operators/expression/type/type';
let mingoInitDone = false;
export function getMingoQuery(
selector
) {
if (!mingoInitDone) {
useOperators(OperatorType.PIPELINE, {
$sort,
$project
});
useOperators(OperatorType.QUERY, {
$and,
$eq,
$elemMatch,
$exists,
$gt,
$gte,
$in,
$lt,
$lte,
$ne,
$nin,
$mod,
$nor,
$not,
$or,
$regex,
$size,
$type,
});
mingoInitDone = true;
}
return new Query(selector);
}
getMingoQuery({
age: {
$gt: 10,
$ne: 50
}
});
from mingo.
Ok, unfortunately the issue is due to weak type of enforcement of the operator function registered for their corresponding types.
Comparison expressions have different signatures when used to query documents directly via Query
or when used in the aggregation pipeline.
You have registered the expression
operator versions of the comparisons for the query
operator type.
import { $eq } from 'mingo/operators/expression/comparison/eq';
import { $ne } from 'mingo/operators/expression/comparison/ne';
import { $gt } from 'mingo/operators/expression/comparison/gt';
import { $gte } from 'mingo/operators/expression/comparison/gte';
import { $lt } from 'mingo/operators/expression/comparison/lt';
import { $lte } from 'mingo/operators/expression/comparison/lte';
These should be
import { $eq } from 'mingo/operators/query/comparison/eq';
import { $ne } from 'mingo/operators/query/comparison/ne';
import { $gt } from 'mingo/operators/query/comparison/gt';
import { $gte } from 'mingo/operators/query/comparison/gte';
import { $lt } from 'mingo/operators/query/comparison/lt';
import { $lte } from 'mingo/operators/query/comparison/lte';
To avoid all of this hassle prefer to use the following as the initialization.
require("mingo")
It would only load the basic operators as defined here
from mingo.
There is no method CreateListFromArrayLike
in mingo
. Is that defined somewhere in your library?
from mingo.
The error comes from sending wrong data into apply
see
according to the stack trace, this comes from the createExpressionOperator()
method of mingo:
from mingo.
Interestingly, running it on the browser returns a different but similar error:
TypeError: Spread syntax requires ...iterable[Symbol.iterator] to be a function
at eval (webpack://rxdb/./node_modules/mingo/es/operators/_predicates.js?:54:16)
at Query.processOperator (webpack://rxdb/./node_modules/mingo/es/query.js?:54:20)
from mingo.
Something funny happening with the transpiler. It should be passing in args
as an array and not a direct value.
from mingo.
It compiles createQueryOperator
correctly
function createQueryOperator(predicate) {
return function (selector, value, options) {
var opts = { unwrapArray: true };
var depth = Math.max(1, selector.split(".").length - 1);
return function (obj) {
// value of field must be fully resolved.
var lhs = (0, util_1.resolve)(obj, selector, opts);
return predicate(lhs, value, __assign(__assign({}, options), { depth: depth }));
};
};
}
but for createExpressionOperator
, it converts the call into an apply
because I use the spread operator.
function createExpressionOperator(predicate) {
return function (obj, expr, options) {
var args = (0, core_1.computeValue)(obj, expr, null, options);
// console.log(args) --> returns the value 10.
return predicate.apply(void 0, args);
};
}
from mingo.
The version of the comparison operators from the expression module must resolve to array as expected by the predicate.apply
generated. The inner function of the createExpressionOperator
should not even be evaluated in your example.
Unfortunately, these are some side effects of some design choices and a lack of good way to assert the type of functions. In a future version, I might consider wrapping operators in classes to get some instance based type checking.
Hope that helps.
from mingo.
I am not able to use require("mingo")
because that includes all operators in my javascript bundle.
Also importing all operators directly from operators/query
will end up in adding all operators to the webpack bundle. like import {$and } from 'mingo/operators/query';
I now changed all imports like you described and it works. Thank you for your time.
from mingo.
Using require("mingo")
only adds the basic operators (comparison, booleans, and query) in your bundle. You can do also do require("mingo/init/basic")
which gives the same effect and is more explicit.
from mingo.
Related Issues (20)
- $round is rounding down to even numbers even when it's above the .5 threshold HOT 4
- Regression in string matching in 4.3 HOT 7
- Question: Why has the generic type for Cursor been removed? HOT 3
- updateObject does not work for array of objects with the $pull operator HOT 8
- Add support for $median (aggregation) HOT 1
- Add support for $percentile (aggregation) HOT 2
- Add support for $bitAnd (aggregation)
- Add support for $bitNot (aggregation)
- Add support $bitOr (aggregation)
- Add support for $bitXor (aggregation)
- updateObject fails when the $exists operator is used with $pull HOT 2
- $push with updateObject does not create the array if the fields does not exist HOT 1
- $inc with updateObject does not create the field if it doesn't exist HOT 1
- aggregate() $group stage with mongodb object id as group key only creates one single group HOT 1
- aggregate() $project stage modifies original collection when using negative projection on nested field HOT 2
- TypeError: Cannot convert undefined or null to object HOT 9
- AWS SSO HOT 2
- query HOT 1
- $project step omits referenced properties when matching property exists in incoming data HOT 3
- Basic query operators not loaded by default for update operation. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mingo.