applying search in mongodb using pymongo using python code example

Example 1: searching in database using java

import java.sql.*;

public class jdbcConn {
   public static void main(String[] args) throws Exception {
      Class.forName("org.apache.derby.jdbc.ClientDriver");
      Connection con = DriverManager.getConnection(
         "jdbc:derby://localhost:1527/testDb","username", "password");
      
      Statement stmt = con.createStatement();
      String query[] = {
         "SELECT * FROM emp where id = 1", 
         "select name from emp where name like 'ravi_'", 
         "select name from emp where name like 'ravi%'" 
      };
      
      for(String q : query) {
         ResultSet rs = stmt.executeQuery(q);
         System.out.println("Names for query "+q+" are");
         
         while (rs.next()) {
            String name = rs.getString("name");
            System.out.print(name+"  ");
         }
         System.out.println();
      }
   }
}

Example 2: fetch api based on id nodejs and mongodb

// Import expresslet express = require('express');// Import Body parserlet bodyParser = require('body-parser');// Import Mongooselet mongoose = require('mongoose');// Initialise the applet app = express();// Import routeslet apiRoutes = require("./api-routes");// Configure bodyparser to handle post requestsapp.use(bodyParser.urlencoded({    extended: true}));app.use(bodyParser.json());// Connect to Mongoose and set connection variablemongoose.connect('mongodb://localhost/resthub', { useNewUrlParser: true});var db = mongoose.connection;// Added check for DB connectionif(!db)    console.log("Error connecting db")else    console.log("Db connected successfully")// Setup server portvar port = process.env.PORT || 8080;// Send message for default URLapp.get('/', (req, res) => res.send('Hello World with Express'));// Use Api routes in the Appapp.use('/api', apiRoutes);// Launch app to listen to specified portapp.listen(port, function () {    console.log("Running RestHub on port " + port);});

Tags:

Java Example