archr / mongoose-datatables Goto Github PK
View Code? Open in Web Editor NEWServer side dataTable request.
Server side dataTable request.
For example, this options parameter does not work:
var options={
find:{ $or:[ {'status':0}, {'status':2} ]},
search: {
value: "hello",
fields: ['name','city']
}
};
It seems the searching fields conditions are added to the $or of the find, but I think this is not the expected behaviour. Instead, it should create an $and element containing two $or (one for the find and another one for the search fields), like this:
var options={
find:{
$and:[
{$or:[ {'status':0}, {'status':2} ] },
{$or:[ {'name':{'$regex': 'hello', '$options': 'i'}}, {'city':{'$regex': 'hello', '$options': 'i'}} ] }
}
}
};
I think an "else" is needed in the "if" of the line 37 of mongoose-datatables.js
Hi,
I couldn't find support for multiple searching on individual columns:
https://datatables.net/examples/api/regex.html
There is support for global search only.
I solved it but I don't have pull-request permissions.
Thanks
DeprecationWarning:
collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.estimatedDocumentCount
In mongoose-datatables.js line 82
Change:
.all([query.exec(), thisSchema.count(find)])
To:
.all([query.exec(), thisSchema.countDocuments(find)])
Hi there,
I want to search from store and user collection but i am not getting data when search
I have three collection and below my schema
var mongoose = require('mongoose');
var dataTables = require('mongoose-datatables');
var storeSchema = new mongoose.Schema({
store_name: String
});
storeSchema.plugin(dataTables);
module.exports = mongoose.model("Stores", storeSchema, 'tbl_stores');
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');
var dataTables = require('mongoose-datatables');
var userSchema = mongoose.Schema({
firstname: {type: String},
lastname: {type: String},
email: {type: String, unique: true},
password: {type: String}
});
userSchema.plugin(dataTables);
module.exports = mongoose.model('User', userSchema, 'users');
var mongoose = require('mongoose');
var dataTables = require('mongoose-datatables');
var userStoreSchema = new mongoose.Schema({
store_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Stores'
},
user_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
});
userStoreSchema.plugin(dataTables);
module.exports = mongoose.model("storeUser", userStoreSchema, 'tbl_store_user');
This is my code for fetching data,when i am searching data from store name i am getting store data
var mongoose = require('mongoose');
var User = require('../models/dbuser');
var Stores = require('../models/dbstore');
var storeUser = require('../models/dbuserstore');
var order = req.body.order[0].column;
var dir = req.body.order[0].dir;
var col = req.body.columns[order].data;
jsObj = {};
jsObj[col] = dir;
storeUser.dataTables({
limit: req.body.length,
skip: req.body.start,
populate:
[ { path: 'store_id'}, { path: 'user_id'}],
select: {_id: true, store_id: true, user_id: true},
search: {
value: req.body.search.value,
field: ['store_id']
},
sort: jsObj
}).then(function (table) {
res.json({
data: table.data,
recordsFiltered: table.total,
recordsTotal: table.total
});
});
Please help me out from this issue.
Thanks in advance
I've been going round in circles. Could you please tell me what I should use for URL: String?
ajax: {
url: '/', <<<<<<<<???
type: 'POST'
},
sorry i didnt know where elses to ask the question
Hi,
This is my query: 'user':'wer'.
I expected it to return all the data with user named 'wer' only. But instead it return any data where the name started with 'wer' (e.g: werr, werww, wer*). I wish to know if its normal.
below are the code with sources that i found and write at nodejs server. Thank you.
`
//https://github.com/archr/mongoose-datatables
// https://github.com/archr/mongoose-datatables/blob/master/example/index.js
Model.dataTables({
limit: req.body.length,
skip: req.body.start,
order: req.body.order,
columns: req.body.columns,
search: {
value: username,
fields: ['user']
},
sort: {
date:-1
}
}).then(function (table) {
res.json({
data:table.data,
recordsFiltered: table.total,
recordsTotal: table.total
});
})
})`
Hi,
It is possible to specify a query, e.g: /user/:id, or /courses/:id/students.
Thanks
The current version of Mongoose-datatables doesn't seem work with the lastest mongoose (4.1.0). Can you point the mismatch?
model:
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var dataTables = require('mongoose-datatables');
var scoresSchema= new Schema({
name: String,
score: Number
});
scoresSchema.plugin(dataTables, {
totalKey: 'recordsTotal',
dataKey: 'data',
});
mongoose.model('ScoresSchema', scoresSchema);
express:
exports.scoresAjax = function (req, res) {
var columns = [];
columns = ['name', 'score'];
var sort = {};
if (req.body.order) {
req.body.order.forEach(function (order) {
var column = columns[order.column];
sort[column] = order.dir === "desc" ? -1 : 1;
})
}
Score.dataTables({
limit: req.body.length,
skip: req.body.start,
search: {
value: req.body.search.value,
fields: ['name', 'score']
},
sort: sort,
select: 'name score'
}, function (err, table) {
if (err) {
return res.json([])
} else {
var data = [];
table.data.forEach(function (obj) {
data.push([obj.name, obj.score]);
})
table.data = data;
table.recordsFiltered = table.recordsTotal;
res.json(table); // table.total, table.data
});
}
}
i get an error says
Error: Can't use $options with Number.
at SchemaNumber.castForQuery (/home/bitnami/admin/node_modules/mongoose/lib/schema/number.js:278:13)
at cast (/home/user/app/node_modules/mongoose/lib/cast.js:213:39)
at cast (/home/user/app/node_modules/mongoose/lib/cast.js:36:18)
at Query.cast (/home/user/app/node_modules/mongoose/lib/query.js:2741:10)
at Query._count (/home/user/app/node_modules/mongoose/lib/query.js:1380:10)
at /home/user/app/node_modules/kareem/index.js:239:8
at /home/user/app/node_modules/kareem/index.js:18:7
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
and also when there is an error the callaback is called twice so i get an error:
Error: Can't set headers after they are sent.
Hi,
i am really confused as i want to use aggregate pipeline with mongoose-datatables.
This is my code
aModel.dataTables({
find: {isCertified: { $ne: null}},
limit: req.body.length,
skip: req.body.start,
search: {
value: req.body.search.value,
fields: ['status', 'user'],
andQuery: andQuery,
},
sort: {
[req.body.columns[req.body.order[0].column].data]: dir
},
populate: [
{ path: 'user' }
]
})
What i want is to do a left join
something like this
db.orders.aggregate([
{
$lookup:
{
from: "products",
localField: "products",
foreignField: "_id",
as: "productObjects"
}
}
])
my question is can i use aggregate with mongoose-datatables?
if yes, then how can i use it ?
if no, then are there any other method to do something like this/
As much as I've seen, this tool does not support the full search() API:
(from https://datatables.net/reference/option/search)
search.caseInsensitive - Indicate is case-insensitive sorting should be performed.
search.regex - Treat the search as a regular expression or not
search.smart - Use DataTables' smart filtering or not
Additionally, to set an initial filter:
search.search - Set an initial global filter.
Hello @archr, I have problem when searching more than one field. This is my code:
User.dataTables({
find: {
$or: findRole,
},
limit: req.query.length,
skip: req.query.start,
search: {
value: req.query.search.value,
fields: ['email'],
},
sort: sort,
}, (err, table) => {
table.recordsFiltered = table.recordsTotal;
res.json(table);
});
Below the model code:
UserSchema.plugin(dataTables, {
totalKey: 'recordsTotal',
dataKey: 'data',
});
Thanks, sorry for my bad english
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.