query string for querying a sub-entity. Is this possible ?
When i perform a get request this is what i get
http://localhost:3000/api/post
[
{
"_id": "5529866ae1ad43bd95d6b335",
"title": "amazon My Post",
"content": "dasdd This is a post with some tags",
"tags": [
{
"name": "amazon"
},
{
"name": "tracking"
}
]
},
{
"_id": "55298674e1ad43bd95d6b336",
"title": "flipkart My Post",
"content": "dasdjkjfkajd This is a post with some tags",
"tags": [
{
"name": "flipkart"
},
{
"name": "tracking"
}
]
}
]
I want to perform something like this http://localhost:3000/api/post/?tags.name=amazon
it should return me
[
{
"_id": "5529866ae1ad43bd95d6b335",
"title": "amazon My Post",
"content": "dasdd This is a post with some tags",
"tags": [
{
"name": "amazon"
},
{
"name": "tracking"
}
]
}
]
Currently it returns me all records.
Is this possible ? or can i restructure my schema to achieve this ?
My code is as follows
Server.js
// Dependencies
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
// MongoDB
mongoose.connect('mongodb://localhost/NodeMongo');
// Express
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
//Enable CORS
app.all('*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
app.use('/api',require('./routes/api'));
// Start Server
app.listen(3000);
console.log('Api is running on port 3000');
api.js
// Dependencies
var express = require('express');
var router = express.Router();
Post.methods(['get', 'post', 'put', 'delete']);
Post.register(router, '/post');
module.exports = router;
post.js
// Dependencies
var restful = require('node-restful');
var mongoose = restful.mongoose;
//Schema
var postSchema = new mongoose.Schema({
title: { type: 'String', required: true },
content: { type: 'String', required: true },
tags: [{ name : {type: 'String'} }]
});
//Return model
module.exports = restful.model('Posts', postSchema);
Same trouble here. After some time i came up with working code :
query = {};
query['local.role'] = params.role;
if you do a get request with this, it will work. I want to filter this with a regex, that is not working
Nailed it!
localhost:8080/api/v1/users?local.email__regex=rom
will look for all elements with local['email'] containing 'rom' to write full regexp, i believe you need to add %2F instead of the / since its url params.
Will give it a try and get back. Thanks for your reply.
@sanketss84 did you have solved your problem?
@romain10009 looking the #99 how is it possible to solve it?