我的应用程序中有一部分可以指定一些过滤器来检索某些数据。但并非所有过滤器都是必需的,因此我可以将其中一些过滤器留空,并且查询不会使用它们。我怎样才能在 mongoDB 中实现这一点。提前致谢。
客户端:
$('#filter').click(function(e){
e.preventDefault();
var filters = JSON.stringify({ Marca : $('#Marca').val(), Modelo : $('#Modelo').val(), Fecha : $('#Fecha').val()});
$.ajax({
type: 'POST',
data: filters,
url: '/filterFees',
contentType: 'application/json'
}).done(function( response ) {
if(response.msg === ''){
filterFees(response.data);
}
else {
alert('Error: ' + response.msg);
}
})
})
Run Code Online (Sandbox Code Playgroud)
node.js(使用僧侣):
app.post('/filterFees', function(req, res){
var db = req.db;
var collection = db.get('Fees');
collection.find({'Marca' : req.body.Marca, 'Modelo' : req.body.Modelo, 'Fecha' : req.body.Fecha, },{},function(err,docs){
res.send((err === null) ? { msg: '', data : docs } : …Run Code Online (Sandbox Code Playgroud) 我使用fsnode.js 的模块来读取目录的所有文件并返回它们的内容,但我用来存储内容的数组总是空的.
服务器端:
app.get('/getCars', function(req, res){
var path = __dirname + '/Cars/';
var cars = [];
fs.readdir(path, function (err, data) {
if (err) throw err;
data.forEach(function(fileName){
fs.readFile(path + fileName, 'utf8', function (err, data) {
if (err) throw err;
files.push(data);
});
});
});
res.send(files);
console.log('complete');
});
Run Code Online (Sandbox Code Playgroud)
ajax功能:
$.ajax({
type: 'GET',
url: '/getCars',
dataType: 'JSON',
contentType: 'application/json'
}).done(function( response ) {
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
提前致谢.
所以我有一个登录页面,我必须实现一个验证:'如果用户是“sa”,那么它应该使用该用户凭据连接到数据库',这意味着我必须修改我的SqlConnection对象的凭据:
if(username.Equals("sa", StringComparison.OrdinalIgnoreCase))
{
var securePassword = new System.Security.SecureString();
foreach(char character in password)
{
securePassword.AppendChar(character);
}
securePassword.MakeReadOnly();
var credentials = new SqlCredential(username, securePassword);
sqlConn.Close();
sqlConn.Credential = credentials;
sqlConn.Open();
return true;
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了一个例外,sqlConn.Credential = credentials;即使该财产不是readonly
InvalidOperationException:不能将凭据与用户 ID、UID、密码或 PWD 连接字符串关键字一起使用。
有没有其他方法可以更改Credentials属性?
提前致谢。
我有一个链接到产品页面的按钮,就像这样......
<a href="/product.html" id="link"><button>Buy This</button></a>
Run Code Online (Sandbox Code Playgroud)
当我选中一个方框时,我需要更改href的值.这就是我到目前为止所拥有的
document.getElementById(#option1).checked = true;
document.getElementById(#link).value = '/product/option1.html';
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
谢谢!:)