Answers for "query mongodb"

3

query mongodb

db.inventory.find( { status: "D" } )
Posted by: Guest on June-30-2020
0

Mongo-queries

db.course
.find({price: {$set: {$gte: 8, $lte: 28} }})
.limit(8)
.sort({name: 1})
.select({name: 1, tags: 1})

// operators: 
// Comparison: 
//      $eq, $gt, $gte, $lt, $lte, $ne: a specified value
//      $in, $nin                 : the values specified in an array


// Logical: $and, $not, $nor, $or
// Element: $exists, $type
.......
Posted by: Guest on August-09-2021
0

query mongodb

db.inventory.find( {} )
Posted by: Guest on June-30-2020
0

query mongodb

const Books = require("Books.js")
async getBooks(req, res, next) {
    let query;

    // Copy req.query
    let reqQuery = { ...req.query };

    // Fields to exclude
    const removeFields = ["select", "sort"];

    // Loop over removeFields and delete them from reqQuery
    removeFields.forEach(param => delete reqQuery[param]);

    // Create query string
    let queryStr = JSON.stringify(reqQuery);

    // Create operators ($gt, $gte, etc)
    queryStr = queryStr.replace(
      /\b(gt|gte|lt|lte|in)\b/g,
      match => `$${match}`
    );

    // Find resource
    query = Books.findQuery(JSON.parse(queryStr));

    // Select Fields
    if (req.query.select) {
      const fields = req.query.select.split(",").join(" ");
      query = query.select(fields);
    }

    // Sort
    if (req.query.sort) {
      const sortBy = req.query.sort.split(",").join(" ");
      query = query.sort(sortBy);
    } else {
      query = query.sort("-createdAt");
    }

  
    // Pagination
    const page = parseInt(req.query.page, 10) || 1;
    const limit = parseInt(req.query.limit, 10) || 10;
    const startIndex = (page - 1) * limit;
    const endIndex = page * limit;
    const total = await Books.countDocuments();
    query = query.skip(startIndex).limit(limit);
  
    // Executing query
    let books = await query;
  
  	
    // Pagination result
    const pagination = {};

    if (endIndex < total) {
      pagination.next = {
        page: page + 1,
        limit,
      };
    }

    if (startIndex > 0) {
      pagination.prev = {
        page: page - 1,
        limit,
      };
    }

    res.status(200).json({
      success: true,
      count: books.length,
      pagination,
      data: books,
    });
  
  
  }
Posted by: Guest on October-06-2021
-1

where query mongodb

db.players.find( { $where: function() {   return (hex_md5(this.name) == "9b53e667f30cd329dca1ec9e6a83e994")} } );
Posted by: Guest on July-26-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language