-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
After indexing a field that's an object type, the value will become empty after inserting.
I cannot use objects for the _id field because of the same issue
I believe the issue is maybe in this function
react-native-local-mongodb/lib/indexes.js
Lines 13 to 34 in b5955be
| /** | |
| * Type-aware projection | |
| */ | |
| function projectForUnique(elt) { | |
| if (elt === null || Array.isArray(elt)) { | |
| return '$null'; | |
| } | |
| if (typeof elt === 'string') { | |
| return '$string' + elt; | |
| } | |
| if (typeof elt === 'boolean') { | |
| return '$boolean' + elt; | |
| } | |
| if (typeof elt === 'number') { | |
| return '$number' + elt; | |
| } | |
| if (util.isArray(elt)) { | |
| return '$date' + elt.getTime(); | |
| } | |
| return elt; // Arrays and objects, will check for pointer equality | |
| } |
export function testIndex(): void {
db.loadDatabase();
db.remove({}, { multi: true });
db.ensureIndex({ fieldName: 'key' }, (err) => {
if (err != null) LOG.error('ensureIndex err:', err);
});
db.insert({ key: { a: 1 } }, (err, doc) => {
if (err != null) LOG.error('a1:', err);
else LOG.info('a1 doc added:', doc);
});
db.insert({ key: { a: 2 } }, (err, doc) => {
if (err != null) LOG.error('a2:', err);
else LOG.info('a2 doc added:', doc);
});
db.insert({ key: { b: 1 } }, (err, doc) => {
if (err != null) LOG.error('b1:', err);
else LOG.info('b1 doc added:', doc);
});
db.insert({ key: { b: 2 } }, (err, doc) => {
if (err != null) LOG.error('b2:', err);
else LOG.info('b2 doc added:', doc);
});
db.count({}, (_, count) => {
LOG.info(`count: ${count}`);
});
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
