Skip to content

Instantly share code, notes, and snippets.

@lineus lineus/ambikarajbadal.js Secret
Created Jul 11, 2018

What would you like to do?
you can pass a variable into queries
#!/usr/bin/env node
'use strict';
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true });
const conn = mongoose.connection;
const Schema = mongoose.Schema;
const schema = new Schema({
name: String
const Test = mongoose.model('test', schema);
const test = new Test({
name: 'Billy'
function getDoc(str) {
return Test.findOne({ name: str });
async function run() {
await conn.dropDatabase();
let found = await getDoc('Billy');
return conn.close();
$: ./ambikarajbadal.js
{ _id: 5b45f98a4b23122ca7bbc88d, name: 'Billy', __v: 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.