new到目前为止,我一直在使用JavaScript中的关键字.我一直在阅读Object.create,我想知道是否应该使用它.我不太明白的是我经常需要运行构造代码,因此我看不到Object.create它将如何工作,因为它不会触发任何运行的函数.
谁能告诉我,在哪种情况下我应该使用Object.create而不是new?
我下载了WAMP服务器版本2.2并安装在Windows 7 64位机器上.
但问题是它引发了以下细节的错误:
Aestan Tray Menu
Could not execute menu item (internal error)
[Exception] Could not perform service action:
The service has not been started
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我它究竟意味着什么,如果它是已知的解决方案?
我有一个大约有5000行的大桌子.我使用以下jquery片段在此表中搜索特定文本.
function searchTable(inputVal) {
var table = $('.table');
table.find('tr').each(function(index, row) {
var allCells = $(row).find('td');
if(allCells.length > 0) {
var found = false;
allCells.each(function(index, td) {
var regExp = new RegExp(inputVal, 'i');
if(regExp.test($(td).text())) {
found = true;
return false;
}
});
if(found == true) {
$(row).show();
} else {
$(row).hide();
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
现在这个脚本需要一些时间来执行,因为它遍历每行的每个单元格.考虑到表中连续有6个单元格,迭代总数几乎是6*5000 = 30000!
是否有任何建议来优化此代码段?
场景:我们从SQL Server获取行到C#.Net控制台应用程序,并通过存储过程对从SQL Server检索到的数据执行操作; 执行操作后,使用C#-MongoDB-Driver将新数据存储到MongoDB中.
问题:有数十亿行.我的存储过程包含如下查询:
select * from table_name
Run Code Online (Sandbox Code Playgroud)
为了计算出一些批处理逻辑,没有标识列,也没有任何日期列等.
信息:截至目前,应用程序正在获取最多3500 - 5000条记录并存储到MongoDB中,然后抛出错误,如下所示:
System.Runtime.InteropServices.SEHException(0x80004005):外部组件引发了异常.
问题:任何人都可以向我建议一些逻辑来解决从SQL Server批量读取/获取的问题吗?
场景:考虑我有一个JSON文档如下:
{
"name": "David",
"age" : 78,
"NoOfVisits" : 4
}
Run Code Online (Sandbox Code Playgroud)
问题:我想改变文档中字段的顺序/顺序,比如我想要age,NoOfVisits然后最后name.
截至目前,我将值存储在临时变量中,删除字段并重新创建相同的字段.由于重新分配不起作用:(
我是按照以下方式做到的:
temp = doc["age"];
delete doc['age'];
doc["age"] = temp;
temp = doc["NoOfVisits "];
delete doc['NoOfVisits '];
doc["NoOfVisits"] = temp;
temp = doc["name"];
delete doc['name'];
doc["name"] = temp;
Run Code Online (Sandbox Code Playgroud)
这样我就可以获得所需的有序JSON文档.这个要求是特殊的,但我仍然需要一些有效的解决方案
问题:有人可以用有效的方法帮助实现同样的目标吗?
场景:考虑我有多个方法执行不同的任务并由不同的开发人员处理.我正在尝试进行泛型方法调用,如果发生错误则会记录该方法.所以需要我必须记录行号,方法名称等.
我写了一个泛型函数,如下:
function enterLog(sourcefile, methodName, LineNo)
{
fs.appendFile('errlog.txt', sourcefile +'\t'+ methodName +'\t'+ LineNo +'\n', function(e){
if(e)
console.log('Error Logger Failed in Appending File! ' + e);
});
}
Run Code Online (Sandbox Code Playgroud)
因此,对上述方法的调用必须传递源文件,方法名称和行号,这可能在开发期间的任何时间点发生变化.
例如,使用硬编码值调用方法:
enterLog('hardcodedFileName.js', 'TestMethod()', '27');
Run Code Online (Sandbox Code Playgroud)
问题:是否更好地对所需的值进行硬编码(如上例所示),或者是否有任何方法可以在Node.js中以任何方式获取方法名称和行号?
考虑以下是我的文档存储在集合中 Users
{
_id : "User1",
joined : ISODate("2011-03-02"),
likes : {
sublikes: [
{WebsiteID:'001': WebsiteName: 'ABCD'},
{WebsiteID:'002': WebsiteName: '2BC2'},
{WebsiteID:'003': WebsiteName: '3BC3'},
//...........
//...........
{WebsiteID:'999999': WebsiteName: 'SOME_NAME'}
]
}
}
Run Code Online (Sandbox Code Playgroud)
现在使用mongodb聚合框架我需要获取它
collection.aggregate([
{ $project: {
_id: 1,
"UserID": "$_id",
"WebsiteName": "$likes.sublikes[0]['WebsiteName']"
}
},
{ $match: { _id: 'User1'} }
], function (err, doc) {
///Not able to get the WebsiteName: 'ABCD'
});
Run Code Online (Sandbox Code Playgroud)
如果我使用$unwind文档变成批量(特别是在上面的情况下),所以我不想放松它只获取数组中的第一项(不论其他人)
任何人都可以给我提示如何访问并重命名该字段?
"WebsiteName": "$likes.sublikes.0.WebsiteName".没工作:-(
更新 2:未解决的问题 - https://jira.mongodb.org/browse/SERVER-4589
截至目前$at不起作用.抛出错误:
{ …Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?';
console.log(myVar);
Run Code Online (Sandbox Code Playgroud)
输出:
This is my text.
And other information.
How to console.log
?
Run Code Online (Sandbox Code Playgroud)
我如何安慰\n,\r&\n\r?
请考虑以下代码,我用它来从我的本地MongoDB服务器获取数据.
var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');
var db = new Db('test', new Server('localhost', 27017));
db.open(function(err, db) {
db.createCollection('simple_limit_skip_find_one_query', function(err, collection) {
assert.equal(null, err);
collection.insert([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) {
assert.equal(null, err);
collection.findOne({a:1}, {fields:{b:1}}, function(err, doc) {
// I got the read document in the object 'doc'
});
});
});
}); …Run Code Online (Sandbox Code Playgroud) node.js ×4
mongodb ×3
javascript ×2
c# ×1
c#-4.0 ×1
console.log ×1
ecmascript-5 ×1
jquery ×1
json ×1
sql-server ×1
wamp ×1
wampserver ×1