我正在将我的用户帐户系统从MongoDB迁移到mySQL。一切都很好,直到我在登录时反序列化我的用户。一旦我达到这一点,我得到:
TypeError:无法读取属性'符号(Symbol.iterator)'的 未定义。
在我的deserialize函数中,我有两个函数,一个引用mySQL,一个引用我的MongoDB查询。
当我启用mySQL函数时,我收到错误。但是当我使用硬编码的_id引用MongoDB函数时。我获得了成功。
请帮助..这让我挂了至少5个小时。
import UIKit
class VideoSearchController: UITableViewController, UISearchResultsUpdating {
var searchResults: NSDictionary = [:]
let searchController = UISearchController(searchResultsController: nil)
// Can't override
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath) as! SearchTableCell
cell.videoTitle.text = "This is the title"
cell.viewCount.text = "1,234,567"
cell.channelName.text = "benlvn"
let url = URL(string: "https://i.redd.it/78r3ttko3nnz.jpg")
let data = try? Data(contentsOf: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
cell.thumbnail.image = UIImage(data: data!)
return cell
}
// Can't override
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
// Override works
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return searchResults.count
}
override func viewDidLoad() {
super.viewDidLoad()
}
func updateSearchResults(for searchController: UISearchController) {
// TODO
}
func searchBarIsEmpty() -> Bool {
// Returns true if the text is empty or nil
return searchController.searchBar.text?.isEmpty ?? true
}
}
我的登录登录是:
passport.deserializeUser(async function(id, done) {
dbs.query('SELECT * FROM users WHERE `_id` = "' + id + '";', function(err, user){
if (err) throw err;
var u = JSON.parse(JSON.stringify(user[0]));
console.log('attempted return')
console.log(u); //Returns an obj
done(err, u);
});
User.getUserById("59c2fc904300338c08a8359c", function(err, user) {
console.log(user);
//done(err, user);
});
});