New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.find does not work #28
Comments
@sibelius
assuming that is in place you can do the following: // create a v4 uuid and wrap it in an MUUID (this is a shortcut for convenience)
const uuid = MUUID.v4();
// save record and wait for it to commit
await new Data({ uuid }).save();
// retrieve the record
const result = await Data.findOne({ uuid });
// output the result
console.log(result); |
full working source const mongoose = require('mongoose');
const MUUID = require('uuid-mongodb');
// Setup and connect
mongoose.connect('mongodb://localhost/my_mongoose', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const db = mongoose.connection
.on('error', () => console.error('connection error:'))
.once('open', () => {});
async function main() {
const dataSchema = new mongoose.Schema({
uuid: {
type: 'object',
value: { type: 'Buffer' },
default: () => MUUID.v4(),
required: true,
unique: true,
index: true,
},
});
const Data = mongoose.model('Data', dataSchema);
try {
// create a v4 uuid (this simply wraps the fantastic uuid library)
const uuid = MUUID.v4();
// save record and wait for it to commit
await new Data({ uuid }).save();
// retrieve the record
const result = await Data.findOne({ uuid });
// output the result
console.log(result);
} catch (e) {
console.error(e);
} finally {
db.close()
}
}
main(); |
@sibelius let me know if this helps. best! |
Find is working even with pure string , aggregates does not, you need to transform the data yourself Tks |
Can you send an example. I'll see if there is something that that can improve your case |
what worked for us, was this
value as the uuid as a string |
my schema has a field of type Buffer subtype 4 (uuid), then I'm trying to use this package to find data based on uuid
all is returning an empty array
The text was updated successfully, but these errors were encountered: